file data to list

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Aug 28 15:20:00 EDT 2008


Anish Chapagain:
> cnt0001a 29000 xretya 01
> cnt0002a 29850 brishal 02
> cnt0003a 31250 kristal 03
> from here, I need to copy data 29000, 29850, 31250 into a single list
> and
> 01, 02, 03 to another so as to plot graph using these value.

This may offer you a starting point:

>>> line = "cnt0003a 31250 kristal 03"
>>> parts = line.split()
>>> parts
['cnt0003a', '31250', 'kristal', '03']
>>> parts[1], parts[3]
('31250', '03')
>>> map(int, [parts[1], parts[3]])
[31250, 3]

Bye,
bearophile



More information about the Python-list mailing list