Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sorted object in list
#2
Your student example works for me. It gave me [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]. Note that sorted creates a new list, it does not modify the original list. To sort the original list you would want the sort method of the list: student_objects.sort(key=lambda student: student.age).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
sorted object in list - by trois - Mar-01-2019, 03:14 PM
RE: sorted object in list - by ichabod801 - Mar-01-2019, 04:27 PM
RE: sorted object in list - by trois - Mar-04-2019, 09:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  add object and name in list 3lnyn0 4 1,323 Nov-24-2022, 07:33 PM
Last Post: buran
  Failing to print sorted files tester_V 4 1,309 Nov-12-2022, 06:49 PM
Last Post: tester_V
  AttributeError: 'list' object has no attribute 'upper' Anldra12 4 4,955 Apr-27-2022, 09:27 AM
Last Post: Anldra12
  AttributeError: 'list' object has no attribute 'values' ilknurg 4 15,119 Jan-19-2022, 08:33 AM
Last Post: menator01
  set and sorted, not working how expected! wtr 2 1,302 Jan-07-2022, 04:53 PM
Last Post: bowlofred
  AttributeError class object has no attribute list object scttfnch 5 3,510 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  'list' object not callable sidra 5 5,607 Nov-29-2020, 04:56 PM
Last Post: bowlofred
  Creating list of lists from generator object t4keheart 1 2,229 Nov-13-2020, 04:59 AM
Last Post: perfringo
  How to make elements return sorted? notsoexperienced 4 3,271 Sep-24-2020, 09:00 AM
Last Post: perfringo
  TypeError: 'list' object is not callable Python_Mey 1 2,501 Aug-25-2020, 03:56 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020