RE: How to sort over dictionaries

2018-08-30 Thread David Raymond
- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of har...@moonshots.co.in Sent: Thursday, August 30, 2018 4:31 AM To: python-list@python.org Subject: Re: How to sort over dictionaries > > sort = sorted(results, key=lambda res:itemgetter('d

Re: How to sort over dictionaries

2018-08-30 Thread harish
> > sort = sorted(results, key=lambda res:itemgetter('date')) > > print(sort) > > > > > > I have tried the above code peter but it was showing error like > > TypeError: '<' not supported between instances of 'operator.itemgetter' > > and 'operator.itemgetter' > > lambda res:

Re: How to sort over dictionaries

2018-08-30 Thread Peter Otten
har...@moonshots.co.in wrote: > sort = sorted(results, key=lambda res:itemgetter('date')) > print(sort) > > > I have tried the above code peter but it was showing error like > TypeError: '<' not supported between instances of 'operator.itemgetter' > and 'operator.itemgetter' lambda res:

Re: How to sort over dictionaries

2018-08-29 Thread harish
> > > On Wednesday, August 29, 2018 at 11:20:26 AM UTC+5:30, John Ladasky wrote: > >> The top-level object you are showing is a list [], not a dictionary {}. > >> It has dictionaries inside of it though. Do you want to sort the list? > >> > >> Python's sorted() function returns a sorted copy

RE: How to sort over dictionaries

2018-08-29 Thread David Raymond
Well, that's a list of... somethings. So I'm assuming you mean sort a list of dictionaries? foo.sort(key = lambda x: time.strptime(x["date"], "%d-%m-%Y %H:%M")) with , reverse = True in the sort if you want it sorted in reverse -Original Message- From: Python-list

Re: How to sort over dictionaries

2018-08-29 Thread Peter Otten
har...@moonshots.co.in wrote: > On Wednesday, August 29, 2018 at 11:20:26 AM UTC+5:30, John Ladasky wrote: >> The top-level object you are showing is a list [], not a dictionary {}. >> It has dictionaries inside of it though. Do you want to sort the list? >> >> Python's sorted() function

Re: How to sort over dictionaries

2018-08-29 Thread harish
On Wednesday, August 29, 2018 at 11:20:26 AM UTC+5:30, John Ladasky wrote: > The top-level object you are showing is a list [], not a dictionary {}. It > has dictionaries inside of it though. Do you want to sort the list? > > Python's sorted() function returns a sorted copy of a sequence.

Re: How to sort over dictionaries

2018-08-28 Thread John Ladasky
The top-level object you are showing is a list [], not a dictionary {}. It has dictionaries inside of it though. Do you want to sort the list? Python's sorted() function returns a sorted copy of a sequence. Sorted() has an optional argument called "key". Key accepts a second function which