I\'m making a function to modify the elements in a list, but it doesn\'t change all the way through... My function is:
def modifyValues(l):
for x in l:
You should dictionary instead to change item in the list.
>>> def modifyValues(l):
... d = {'a': 1, 'b': 2, 'c': 3}
... modifyl = [k for i in l for k in d if d[k] == i]
... print(modifyl)
...
>>> modifyValues([1, 2, 3, 2, 3, 1, 2, 2])
['a', 'b', 'c', 'b', 'c', 'a', 'b', 'b']
>>>
You can also use the ascii_lowercase constant from string
>>> from string import ascii_lowercase
>>> def modifyValues(l):
... modifyl = [v for i in l for k, v in enumerate(ascii_lowercase, 1) if i == k]
... print(modifyl)
...
>>> modifyValues([1, 2, 3, 2, 3, 1, 2, 2])
['a', 'b', 'c', 'b', 'c', 'a', 'b', 'b']