I am writing a script to swap several items in some lists read from a *.txt file, I tried to write it like this:
i_file = map(lambda x: x.split('|'), open('test.txt', 'r').readlines())
for list in i_file:
list = [list[2], list[0], list[3], list[1], list[4:]]
#Actually I want to update the i_file, but I don't think this will work here
#nevermind, it's just a demostration.
It looks so ugly and hard to read, so I am looking for
somefunc()
that might make my code look like this.
i_file = map(lambda x: x.split('|').somefunc(), open('test.txt', 'r').readlines())
Thanks!!
UPDATE:
input file looks like this:
blahblah1|3141593|Wednesday|John|BlahBlah1|
blahblah2|2714323|Monday|Mike|BlahBlah2|
I want to swap these items in each line in order to rewrite the file into:
3141593|Wednesday|blahblah1|John|BlahBlah1|
blahblah2|Monday|2714323|Mike|BlahBlah2|