[Tutor] pls. help me in sorting and choosing
jfouhy@paradise.net.nz
jfouhy at paradise.net.nz
Thu Aug 11 07:34:47 CEST 2005
Quoting Srinivas Iyyer <srini_iyyer_bio at yahoo.com>:
> 2. I know how to read a tab delim txt file as list but
> not into the tupeles. Apologies for my inexperience.
How are you currently reading the file? --- can you show us some code?
You can create tuples directly. For example:
>>> x = 3
>>> y = 7
>>> t = (x, y)
>>> t
(3, 7)
or:
>>> squares = []
>>> for i in range(10):
... squares.append((i, i**2)) # Note the double parentheses!
...
>>> squares
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25), (6, 36), (7, 49), (8, 64),
(9, 81)]
You can read more about tuples in the python tutorial; section 5.3.
(see http://www.python.org/)
--
John.
More information about the Tutor
mailing list