I want add a variable to some of the items in mylist = ['A', 'B', 'C', 'D', 'E']. I tried something like this example...
for direction in ['Up', 'Down']:
mylist = ['A{}', 'B', 'C{}', 'D', 'E'].format(direction)
for x in mylist:
print x
I want the output to be the following...
AUp
B
CUp
D
E
ADown
B
CDown
D
E
However, this isn't working. Is there a best way to add a variable in a list?
formatworks on a string, not a listprint x.format(direction)in your 2ndforloop and remove theformatfrom your list