I was wondering if there was any way to automatically replace certain elements in a list by other ones, without using an if..else statement for each element ? Something like this :
# before :
aL = ['a', 'b', 'c']
# after :
aL = ['b', 'c', 'd']
I was wondering if there was any way to automatically replace certain elements in a list by other ones, without using an if..else statement for each element ? Something like this :
# before :
aL = ['a', 'b', 'c']
# after :
aL = ['b', 'c', 'd']
One way to do it,
aL = ['a', 'b', 'c','z']
expected = []
for ch in aL:
if ch == 'z':
expected.append(chr(ord(ch)-25))
else:
expected.append(chr(ord(ch) + 1))
print(expected)