Python Forum
Why is this function printing the number of keys in a dictionary?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is this function printing the number of keys in a dictionary?
#6
(Sep-16-2019, 07:20 PM)mafr97 Wrote: We are asked to create a function that will take in a dictionary and return the list in ascending order, either alphabetically or numerically.

What does mean 'return list in ascending order'? List of keys? List of values? List of key-value pairs?

One don't need complicated conversions, dictionary keys can be sorted just like sorted(d), if values needed to be sorted then sorted(d.values()) and to sort list of key-value tuples sorted(d.items()). Sorted function always returns list.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Why is this function printing the number of keys in a dictionary? - by perfringo - Sep-17-2019, 06:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  create empty sets for keys in a dictionary and add values to the set naughtysensei 1 2,521 Nov-03-2020, 08:32 AM
Last Post: DeaD_EyE
  get method within max function for a dictionary Blanchdog 3 1,891 Jul-03-2020, 05:55 PM
Last Post: ndc85430
  How to use value in dictionary as arguments in function gabejohnsonny21 6 3,738 Apr-22-2020, 04:53 PM
Last Post: deanhystad
  Printing a number sequence not working properly deepsen 6 3,023 Oct-12-2019, 07:43 PM
Last Post: deepsen
  printing data from dictionary kiki1113 4 48,035 Nov-20-2017, 04:43 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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