Done without the enumerate function:
(you can remove the other loop, and you don’t have to call return
, python will automatically return None
):
def add_letter(mylist):
for i in range(len(mylist)):
mylist[i] = str(mylist[i]) + randomletter
# Now you can call addletter function
mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9, ];
randomletter="a"
add_letter(mylist)
print(mylist)
3
solved What are some Alternatives to enumerate function in Python?