About python while statement and pop()

Mark H Harris harrismh777 at gmail.com
Thu Jun 12 13:16:19 EDT 2014


On 6/12/14 11:57 AM, Chris Angelico wrote:
>>>>> def poplist(L):
>>          done = False
>>          while done==False:
>>
>>                  yield L[::-1][:1:]
>>                  L = L[::-1][1::][::-1]
>>                  if len(L)==0: done=True
>
> Why not just "while L"?

OK,  here it is with Chris' excellent advice:

 >>> def poplist(L):
	while L:
		yield L[::-1][:1:]
		L = L[::-1][1::][::-1]

		
 >>> L=[1, 2, 3, 4, 5, 6, 7]
 >>> m=[]
 >>> pop = poplist(L)
 >>> for n in poplist(L):
	m.append(n[0])

	
 >>> m
[7, 6, 5, 4, 3, 2, 1]
 >>>


==========  aaaaah  ===================





More information about the Python-list mailing list