functions and dictionary - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: functions and dictionary (/thread-29198.html) |
functions and dictionary - spalisetty06 - Aug-22-2020 Hello, I am using functions, and I am passing the argument as dictionary, is there a way to get the value of the dictionary? I am able to get the keys though. I am interested to get the values from the dictionary. def odd_even(sequence): for x in sequence: print(x) odd_even({ "store1": ["suman"], "store2": ("su") })
RE: functions and dictionary - ndc85430 - Aug-22-2020 Your question doesn't really have anything to do with functions. Do you know how to access values in a dictionary by key? If you just want all the values, regardless of the key, of course there's a way to do that. See the docs to find the relevant method ;). RE: functions and dictionary - perfringo - Aug-22-2020 One can use tools built-in into interactive interpreter. Like: hmm, what methods can I apply to dictionaries? >>> dict. # two times TAB dict.clear( dict.get( dict.mro( dict.setdefault( dict.copy( dict.items( dict.pop( dict.update( dict.fromkeys( dict.keys( dict.popitem( dict.values(There are promising names like items, keys and values. Let's check what values are about: >>> help(dict.values) Help on method_descriptor: values(...) D.values() -> an object providing a view on D's values (END) # press Q-key to exit help RE: functions and dictionary - jefsummers - Aug-22-2020 Change line 2 to for key, value in sequence: Then print keys, values, both, whatever |