[Tutor] casting string to integer in a list of lists
Alan Gauld
alan.gauld at btinternet.com
Fri Jan 9 02:18:25 CET 2009
"culpritNr1" <ig2ar-saf1 at yahoo.co.uk> wrote
> Say I have this nice list of lists:
>
> LoL = [['chrX', '160944034', '160944035', 'gnfX.145.788', '63.60'],
> ['chrX', '161109992', '161109993', 'rs13484104',
> '63.60'],
> Now I want to cast the second and third "columns" from string to
> integer,
> like this
>
> LoL = [['chrX', 160944034, 160944035, 'gnfX.145.788', '63.60'],
> ['chrX', 161109992, 161109993, 'rs13484104', '63.60'],
Being picky that's not really casting that's converting.
Casting is where you take the same set of binary data and treat it
as if it were a different type but without changing the binary.
Conversion is where you actually change the data into a new
representation. Conversion is relatively easy in Python, casting
is a bit more tricky.
Alan G.
More information about the Tutor
mailing list