Sep-16-2019, 07:20 PM
(This post was last modified: Sep-16-2019, 10:01 PM by ichabod801.)
This is a HOMEWORK problem, that I am struggling with and want to understand.
We are asked to create a function that will take in a dictionary and return the list in ascending order, either alphabetically or numerically.
This is my code:
Here is what I get when run the function. I know I don't have an input, but usually it just gives a blank box (I'm running this in Jupiter Lab just to test it). Then I'll run it with an input to test the outcome.
We are asked to create a function that will take in a dictionary and return the list in ascending order, either alphabetically or numerically.
This is my code:
1 2 3 4 5 |
def dictKeysOnly (dictionary): lst = [dictionary] lst = sorted (lst) return (lst) print ( "List in ascending order: " , sorted (dictionary)) |
Output:---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-8-3c0c43693ca8> in <module>
3 lst = sorted(lst)
4 return (lst)
----> 5 print("List in ascending order: ",sorted(dictionary))
NameError: name 'dictionary' is not defined
I usually miss something when I make a function because it's not always super clear to me, but could someone explain how I define my dictionary input. Also why isn't me inputting 'dictionary' in the function defining it as a parameter?