I have a list of strings.
theList = ['a', 'b', 'c']
I want to add integers to strings, the result is this output:
newList = ['a0', 'b0', 'c0', 'a1', 'b1', 'c1', 'a2', 'b2', 'c2', 'a3', 'b3', 'c3']
I want to save this in a .txt file in this format:
a0 b0 c0 a1 b1 c1 a2 b2 c2 a3 b3 c3
Attempt:
theList = ['a', 'b', 'c'] newList = [] for num in range(4): stringNum = str(num) for letter in theList: newList.append(entry+stringNum) with open('myFile.txt', 'w') as f: print>>f, newList
Now I can save the file myFile.txt, but the text in the file reads:
['a0', 'b0', 'c0', 'a1', 'b1', 'c1', 'a2', 'b2', 'c2', 'a3', 'b3', 'c3']
Any advice on more pythonic ways to achieve my goal is greatly appreciated.