appending into a list
Ricardo Aráoz
ricaraoz at gmail.com
Wed Oct 31 12:49:01 EDT 2007
Beema shafreen wrote:
> hi everybody,
> I have a file :
> A B C D E
>
> 2717353 2717412 A_16_P03641964 214 -59
> 2717626 2717685 A_16_P41563655 25 -59
> 2717710 2717754 A_16_P03641965 1250 -44
> 2719004 2719063 A_16_P03641966 -36 -59
> 2719027 2719086 A_16_P21360229 289 -59
> 2719375 2719428 A_16_P03641967 60 -53
> 2719488 2719542 A_16_P21360231 418 -54
> 2719960 2720014 A_16_P03641968 727 -54
> 2720741 2720786 A_16_P03641969 494 -45
> 2721280 2721339 A_16_P03641970 -28 -59
> 2721311 2721370 A_16_P21360234 150 -59
> 2721520 2721569 A_16_P21360235 199 -49
> 2721768 2721821 A_16_P03641971 139 -53
> 2721960 2722004 A_16_P21360237 312 -44
> I need to append the column D and E into a list:
> in such a way that the list should have
> [D,E,D,E,D,E........]
> How do i do it.
>
> regards
> shafreen
>
>>> r = []
>>> for D, E in (i.split()[-2:] for i in open('file')) :
r.append(D)
r.append(E)
>>> r
['214', '-59', '25', '-59', '1250', '-44', '-36', '-59', '289', '-59',
'60', '-53', '418', '-54', '727', '-54', '494', '-45', '-28', '-59',
'150', '-59', '199', '-49', '139', '-53', '312', '-44']
HTH
More information about the Python-list
mailing list