ANN: Dogelog Runtime, Prolog to the Moon (2021)
Mostowski Collapse
bursejan at gmail.com
Wed Sep 15 17:13:00 EDT 2021
Ok you suggested:
>>>items = [1,2,3,4,5,6,7,8,9,0]
>>>for item in items[:-1]:
>>> print(item)
1
2
3
4
5
6
7
8
9
Does this also work for length = 1? Ok let me try:
>>> foo = ["a","b","c"]
>>> for x in foo[:-1]:
... print(x)
...
a
b
>>> foo = ["a"]
>>> for x in foo[:-1]:
... print(x)
...
Oki Doki
Mostowski Collapse schrieb am Mittwoch, 15. September 2021 um 23:10:50 UTC+2:
> And how do you only iterate over n-1 elements?
> I don't need a loop over all elements.
>
> With array slicing?
>
> Someting like:
>
> for item in items[0:len(items)-2]:
> ___print(item)
>
> Or with negative slicing indexes? Problem
> is my length can be equal to one.
>
> And when I have length equal to one, the
> slice might not do the right thing?
>
> LoL
> alister schrieb am Mittwoch, 15. September 2021 um 22:00:30 UTC+2:
> > for item in items:
> > print(item)
More information about the Python-list
mailing list