Python sort sorting tutorial example explained
#python #sorting #sort
# -------------------------------------------------------------------
# sort() method = used with lists
# sort() function = used with iterables
students = (("Squidward", "F", 60),
("Sandy", "A", 33),
("Patrick","D", 36),
("Spongebob","B", 20),
("Mr.Krabs","C", 78))
grade = lambda grades:grades[1]
# students.sort(key=age) # sorts current list
sorted_students = sorted(students,key=grade) # sorts and creates a new list
for i in sorted_students:
print(i)
# -------------------------------------------------------------------
music credits
#python #sorting #sort
# -------------------------------------------------------------------
# sort() method = used with lists
# sort() function = used with iterables
students = (("Squidward", "F", 60),
("Sandy", "A", 33),
("Patrick","D", 36),
("Spongebob","B", 20),
("Mr.Krabs","C", 78))
grade = lambda grades:grades[1]
# students.sort(key=age) # sorts current list
sorted_students = sorted(students,key=grade) # sorts and creates a new list
for i in sorted_students:
print(i)
# -------------------------------------------------------------------
music credits
- Category
- Bro Code
- Tags
- python, python sorting, python sort
Be the first to comment


