problem about list indexing

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sun Nov 26 11:47:30 CET 2006


hollowspook:
> how about indexing 1-7, 10
> [range(1:8),10] will generate [[1, 2, 3, 4, 5, 6, 7], 10], instead of
> [1, 2, 3, 4, 5, 6, 7, 10]

(Note that range(1:8) is a syntax error).

You can join and extend lists as you like:

>>> range(1, 8) + [10]
[1, 2, 3, 4, 5, 6, 7, 10]

See also the list.append and list.extend methods too.

Bye,
bearophile




More information about the Python-list mailing list