Expand|Select|Wrap|Line Numbers
- #define a list called migList
- migList = ['cat', 'dog', 'car', '22']
- #now add 5 to every unit in migList
- for i in range(len(migList)):
- migList[i] = migList[i]*5
- fn = "migList.txt"
- f = open(fn,'w')
- f.write("\n".join(migList))
- f.close()
The only code I can come up with is the following:
Expand|Select|Wrap|Line Numbers
- f = open('migList.txt', 'r')#opens the file and sets it to read
Question 2: When I use integers in the list and try to save using the code above, I get the following error.
Expand|Select|Wrap|Line Numbers
- TypeError: sequence item 0: expected string, int found
I tried the following code which seemed to work.
Expand|Select|Wrap|Line Numbers
- migList[i] = str(migList[i])
Again, thanks for your help, as my eventual goal is to learn enough about manipulating data in python to be able to manipulate some traffic data.