for 루프에서 다음 루프를 진행하지 않고 다음 단어를 처리하기 위해 next()를 사용하고 싶습니다.for 루프를 사용하지 않고 for 루프에서 파이썬 next()를 사용합니다.
words = ["please", "do", "loop", "in", "order"]
for word in words:
print word
checknextword = str(next((word for word in words), None))
따라서, 나는 인쇄 할 :
>>>please
>>>do
>>>loop
>>>in
>>>order
을하지만 코드를 생성합니다
words = ["please", "do", "loop", "in", "order"]
for i,j in map(None, words, words[1:]): #j will contain the next word and None if i is the last element of the list
print i
[OUTPUT]
please
do
loop
in
order
여기에서 수행하려는 작업이 명확하지 않습니다. 예제 출력은'for word in word : print (word)'라는 간단한 형식으로 생성됩니다. –
문제를 재현 할 수 없습니다. – thefourtheye
어쩌면 당신은 다음과 같은 것을 원할 것입니다. http://stackoverflow.com/questions/6822725/rolling-or-sliding-window-iterator-in-python – M4rtini