Jan-25-2018, 03:50 PM
Quote:it does not return every other value of the dictionaryEvery other value of a dictionary doesn't really make sense.
Also, consider the
global
keyword off limits for the next 5 years or so; seriously.It should not be used for anything like this.
Please provide the exact text of the challenge you are trying to solve.
>>> from string import ascii_lowercase as lower >>> my_dict = dict(zip(lower, range(1,27))) >>> my_dict {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4, 'g': 7, 'f': 6, 'i': 9, 'h': 8, 'k': 11, 'j': 10, 'm': 13, 'l': 12, 'o': 15, 'n': 14, 'q': 17, 'p': 16, 's': 19, 'r': 18, 'u': 21, 't': 20, 'w': 23, 'v': 22, 'y': 25, 'x': 24, 'z': 26} >>> odd_entries = {k:v for k,v in my_dict.items() if v % 2} >>> odd_entries {'a': 1, 'c': 3, 'e': 5, 'g': 7, 'i': 9, 'k': 11, 'm': 13, 'o': 15, 'q': 17, 's': 19, 'u': 21, 'w': 23, 'y': 25} >>>