fill a sequence
Tim Peters
tim_one at email.msn.com
Sat Oct 14 02:21:23 EDT 2000
[Johannes Zellner]
> is there somthing like the C++ std::fill()
No.
> e.g. I want to create a sequence of 5 0's
[0] * 5
> a = [0, 0, 0, 0]
a = [0] * 4
"sequence * int" is defined for all Python sequence types (incl. lists,
arrays, tuples and strings).
Advanced trick of the trade:
s * 0
can be used to create an empty sequence of the same type as s, without
needing to know s's type. Slice notation can also be used for that purpose:
s[:0] # i.e., one way to ask for an empty slice
See section "Sequence Types" in the Library Reference Manual.
More information about the Python-list
mailing list