:
>>> from threading import Thread
>>> from time import sleep
>>> liszt = ['first item', 'second item', 'third item', 'fourth item',
... 'plentee more items', "but I'm lazy"]
>>> def thread_one():
... for i in liszt:
... print 'Thread one found "%s"' % i
... sleep(1)
...
>>> def thread_two():
... sleep(0.5)
... print 'Thread two deleting first item.'
... del liszt[0]
... sleep(1)
... print 'Thread two deleting fourth item.'
... del liszt[3]
...
>>> Thread(target=thread_one).start(); Thread(target=thread_two).start()
Thread one found "first item"
Thread two deleting first item.
Thread one found "third item"
Thread two deleting fourth item.
Thread one found "fourth item"
Thread one found "but I'm lazy"
, ; , , , .
, ; , .
State: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Iterator position: ^
.
State: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Iterator position: ^
.
State: [2, 3, 4, 5, 6, 7, 8, 9, 10]
Iterator position: ^
.
State: [2, 3, 4, 5, 6, 7, 8, 9, 10]
Iterator position: ^
.
State: [2, 3, 4, 5, 7, 8, 9, 10]
Iterator position: ^
Et cetera. , , . , , - .
, iter. for x in y iter(y). , iter(liszt) listiterator, , next() , , . , for Python.