Python For Loops (5)

1 Name: #!/usr/bin/anonymous : 2008-04-23 19:36 ID:9DHuaacy

What the fuck is with Python's [code]for loops[/code].

What's the difference between:
[code]
for i in list[0]:

for i in list[0:]:

for i in list[:0]:
[/code]

2 Name: #!/usr/bin/anonymous : 2008-04-23 23:00 ID:Heaven

uh, well...

this isn't a loop question as much as it is a question about slicing. Read http://docs.python.org/tut/node5.html#SECTION005120000000000000000 for how that works.

3 Name: #!/usr/bin/anonymous : 2008-04-23 23:14 ID:M/qGsCYC

we assume that the list is composed of objects that are sequences and thus can be iterated through.
the first statement uses i to iterate through the first or zeroth element
the second creates a slice from the first to the last, which is the whole list. by omitting the second offset, it gets interpreted as: from the zeroth element up to the len(list) or list[0:len(list)]
the third, another slice, is interpreted as list[0:0], which is the zeroth element

this seems correct, although i dont program in python (or any other language for that matter)

4 Name: #!/usr/bin/anonymous : 2008-04-24 01:19 ID:Heaven

Smells like a homework question. Do it yourself.

5 Name: #!/usr/bin/anonymous : 2008-04-24 02:36 ID:Heaven

This board is SLOOOOW

This thread has been closed. You cannot post in this thread any longer.