I did it like that to avoid using the global variable.
Here is the original problem which I solved with a lot of help from Mekire
This seems to not have that issue
# 1) Start with this list:
#['a', 'b', 'c', ..., 'z'}
#
# And create a function that turns it into this dictionary:
#
# {1: 'a', 2: 'b', 3: 'c', ..., 26: 'z'}
#
# 2) Start with this string:
#
# 'abc...z'
#
# And create a function that turns it into this dictionary:
#
# {1: 'a', 2: 'b', 3: 'c', ..., 26: 'z'}
#
# 3) Take one of the above functions and include only the odd numbers / letters:
#
# {1: 'a', 3: 'c', ..., 25: 'y'}
#
# This is hard but you can get it. You'll have to learn about counters. Either:
#
# idx += 1 or for idx, item in enumerate(<list goes here>)
# 1) Start with this list:
#['a', 'b', 'c', ..., 'z'}
#Let's impress Doctor Housman. Instead of writing out the lists manually lets do it programatically shall we?
#Create list of letters
import string
letlist = list(string.ascii_lowercase)
#Create string of letters
letstring = string.ascii_lowercase
#Create list of numbers
list1=[]
for i in range (1, 27):
list1.append(i)
#Create dictionary for part 1
def dictfunc():
zipped =dict(zip(list1,letlist))
dictfunc()
#Create dictionary for part 2
def dictfun2():
zipped2 = dict(zip(list1, letstring))
dictfun2()
def odds_only():
my_dict = dictfunc()
return {k: v for k, v in my_dict.items() if k % 2}
print(odds_only())
Right there I am passing dictfunc to my_dict or are you saying that code is actually not doing anything?
I will look into the return function right now.