Generate special list from file in python -


i have file :

one:two:three four:five:six seven:height:nine 

and on... want parse correctly obtain kind of variable:

myvar = [("one", "two", "three"), ("four", "five", "six"), ("seven", "height", "nine")] 

of course, file isn't stopping @ nine, there's lot more of lines after that.

how can in python ?

thanks !

use list compehension:

with open('filename') f:     myvar = [line.rstrip().split(':') line in f] 

if need list tuples pass line.rstrip().split(':') tuple():

tuple(line.rstrip().split(':')) 

Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -