(Sep-16-2019, 08:13 PM)woooee Wrote: Can't tell from your code because it isn't formatted, but it looks like dictionary is only declared within the function, so is not defined anywhere outside the function. i.e. for the print statement. Also, the function is never called and so will never execute, and there is no reason to sort the list as it has only one item, a dictionary.
My bad, didn't even notice. Here it is:
def dictKeysOnly (dictionary):
>>>lst = [{dictionary}]
>>>lst = sorted(lst)
>>>return (lst)
>>>print("List in ascending order: ",sorted(dictionary))
Edit: I'm not sure how to indent, but everything under the function is indented once.
When I try to call the function, here is what I get back.
dictKeysOnly({"kelly","amber","sophia","henry","zak"})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-25723a87e72e> in <module>
----> 1 dictKeysOnly({"kelly","amber","sophia","henry","zak"})
<ipython-input-3-93a6185952c3> in dictKeysOnly(dictionary)
1 def dictKeysOnly (dictionary):
----> 2 lst = [{dictionary}]
3 lst = sorted(lst)
4 return (lst)
5 print("List in ascending order: ",sorted(dictionary))
TypeError: unhashable type: 'set'
What do you mean by it's not defined outside the function, and how would I fix that? And how would I give it a reason to sort the list.