C is the correct answer as it also saves the result to the variable list. Calling the sorted function does sort the array but does not save it. For sorted to be used it would need to be list = sorted(list).
To achieve the expected output [1, 2, 4, 7] from the list [2, 7, 1, 4], you should use the list.sort() method, which sorts the list in place.
Here is the complete code snippet:
Copy
list = [2, 7, 1, 4]
list.sort() # This sorts the list in place
print(list)
So, the correct line to use is:
C. list.sort()
C is correct because the output expectation must come from print(list) not from the print(sorted(list)). you have to write comment before the print which is list.sort() or you have to write list=sorted(list) which is not option
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
patonoide
3 weeks, 3 days agoakumo
1 month agoKrish2022
1 month, 1 week agoaphg
1 month, 3 weeks agoSam_sgv
3 months, 1 week agoyagebin
3 months, 3 weeks agohovnival
3 months, 3 weeks agoNfyughguygjhg
4 months, 2 weeks agorcptryk
5 months agomldprasad
5 months agoVano1
5 months, 3 weeks agoscriptnone
6 months agoSujPractise
6 months, 3 weeks agochristostz03
8 months agoBiju1
8 months, 1 week agoBiju1
8 months, 1 week ago