What is the best way to print a list with 3 sublists to a file in python? -
i have list "localisation" contains 3 sublists. want print list file each sublist in column.
eg:
>>>print localisation localisation = [['a', 'b', 'c'],['d', 'e', 'f'],['g', 'h', 'i']]
i want file looks like:
a d g b e h c f
(columns can separated single space, tab etc)
at moment doing follows:
with open("rssi.txt") fd: item in localisation: print>>fd, item
is there better way of doing eg single line prints whole list in @ 1 time?
localisation = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] open("rssi.txt") f: f.write('\n'.join(' '.join(row) row in zip(*localisation))) # d g # b e h # c f
>>> localisation = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] >>> zip(*localisation) [('a', 'd', 'g'), ('b', 'e', 'h'), ('c', 'f', 'i')]
Comments
Post a Comment