I am new to Python..
I have a list (names.txt) which is four names:
- Colin
- Gary
- Gibby
- Ross
I would like to output the list from the file, then change the order of the names by one space and save that output at the original "names.txt" file.
i.e.
Run1 would be: Colin Gary Gibby Ross
Run2 would be: Gary Gibby Ross Colin
Run3 would be: Gibby Ross Colin Gary
....and so on.
The code I have so far is able to take the file and output as a list, but I don't know how to move the order by 1 place and save again:
#!/usr/bin/python
# Open a file
with open ('names.txt', 'r') as f:
list1 = f.read().splitlines()
for item1 in list1[0:4]:
print (item1)
f.close()
All help appreciated. Thanks.