Home > other >  Please consult
Please consult

Time:10-28

The last line of code error?

CodePudding user response:

Do you want to use the sort? The sort and sorted,,

CodePudding user response:

reference 1st floor of the new self-study in python reply:
do you want to use is the sort of? The sort and sorted, and

With sorted. The code to write wrong?

CodePudding user response:

The sort and sorted the usage of different,
You sorted usage in line 4 is right
But the sort of usage is the list. The sort ()
Such as: travel. Sort ()

Sort is directly changing the order of the list itself, and sorted is returns a sorted list will not change the order of the original list

CodePudding user response:

references a smile program monkey reply: 3/f
sort and sorted the usage of different,
You sorted usage in line 4 is right
But the sort of usage is the list. The sort ()
Such as: travel. Sort ()

Sort is directly changing the order of the list itself, and sorted is returns a sorted list will not change the order of the original list

How do I call for a travel list sorted (reverse=True) function? Code should be how to write?

CodePudding user response:

python beginners reference 4 floor of the self-taught reply:
Quote: refer to the third floor smiled program monkey reply:
sort and sorted the usage of different,
You sorted usage in line 4 is right
But the sort of usage is the list. The sort ()
Such as: travel. Sort ()

Sort is directly changing the order of the list itself, and sorted is returns a sorted list will not change the order of the original list

How do I call for a travel list sorted (reverse=True) function? Code should be how to write?


 
Reverse_travel=sorted (travel, reverse=True)

CodePudding user response:

refer to fifth floor smiled program monkey reply:
Quote: python beginners reference 4 floor of the self-taught reply:

Quote: refer to the third floor smiled program monkey reply:
sort and sorted the usage of different,
You sorted usage in line 4 is right
But the sort of usage is the list. The sort ()
Such as: travel. Sort ()

Sort is directly changing the order of the list itself, and sorted is returns a sorted list will not change the order of the original list

How do I call for a travel list sorted (reverse=True) function? Code should be how to write?


 
Reverse_travel=sorted (travel, reverse=True)

Have solve the problem, thank you very much in your busy schedule for my answer.
  • Related