Rewrite the list and print it

Asked 1 years ago, Updated 1 years ago, 77 views

Use index 2 column and sort it out in descending order I wrote [:3] because I wanted only the top 3 to come up It will be printed in a line.

If you know how to do it, please leave a comment.

mylist.sort(key=lambda x:x[2], reverse=True)
print( mylist [:3] )

python python3.6

2022-09-21 10:10

2 Answers

You can print one by one.

for e in mylist[:3]:
  print(e)


2022-09-21 10:10

There are also the following methods.

print(*mylist[:3], sep='\n') 


2022-09-21 10:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.