Re: iterating over list with one mising value

2012-02-07 Thread Steven D'Aprano
(Apologies in advance for breaking threading, but the original post in this thread doesn't appear for me.) > On Tue, Feb 7, 2012 at 5:27 AM, Sammy Danso > wrote: >> >> Hello experts, >> I am having trouble accessing the content of my list. my list content >> has 2-pair value with the exception o

Re: iterating over list with one mising value

2012-02-07 Thread Arnaud Delobelle
On 7 February 2012 22:57, Dennis Lee Bieber wrote: > On Tue, 7 Feb 2012 21:37:20 +, Arnaud Delobelle > wrote: > > >> >>Your list is flat so the unpacking fails.  For it to work, you need >>your list to be of the form: >> >>    wordFreq2 = [('with', 3), ('which', 1), ('were', 2), ('well', 1)]

Re: iterating over list with one mising value

2012-02-07 Thread Aaron France
On 02/07/2012 11:09 PM, Mark Lawrence wrote: On 07/02/2012 21:25, Aaron France wrote: for i in range(0, len(x), 2): print x[i-1], x[i] x = ['with', 3, 'which', 1, 'were', 2, 'well', 1, 'water', 1, 'was', 4, 'two', 1, 'to', 2, 'through', 1, 'thlabour', 1, 'these', 1, 'theat', 1, 'the', 8, '

Re: iterating over list with one mising value

2012-02-07 Thread Mark Lawrence
On 07/02/2012 21:25, Aaron France wrote: for i in range(0, len(x), 2): print x[i-1], x[i] x = ['with', 3, 'which', 1, 'were', 2, 'well', 1, 'water', 1, 'was', 4, 'two', 1, 'to', 2, 'through', 1, 'thlabour', 1, 'these', 1, 'theat', 1, 'the', 8, 'tetanus', 1, 'started', 1, 'size', 1, 'scent',

Re: iterating over list with one mising value

2012-02-07 Thread Arnaud Delobelle
On 7 February 2012 20:23, Sammy Danso wrote: > > Hi Expert, > Thanks for your responses and help. thought I should provide more information > for clarity. Please don't top-post. > Please find the error message below for more information > >    for (key, value) in wordFreq2: > ValueError: need m

Re: iterating over list with one mising value

2012-02-07 Thread Chris Angelico
On Wed, Feb 8, 2012 at 8:25 AM, Aaron France wrote: > for i in range(0, len(x), 2): >    print x[i-1], x[i] I think you want x[i], x[i+1] here, but in any case, this is a fairly standard non-Python way to do this sort of thing. There's a variety of more Pythonic ways to loop, but every now and th

Re: iterating over list with one mising value

2012-02-07 Thread Tim Chase
Thanks for your responses and help. thought I should provide more information for clarity. It sounds like you want the "grouper" function as defined here: http://docs.python.org/library/itertools.html#recipes which does what you describe. -tkc -- http://mail.python.org/mailman/listinfo/pyth

Re: iterating over list with one mising value

2012-02-07 Thread Aaron France
On 02/07/2012 10:13 PM, MRAB wrote: On 07/02/2012 20:23, Sammy Danso wrote: Hi Expert, Thanks for your responses and help. thought I should provide more information for clarity. > Please find the error message below for more information for (key, value) in wordFreq2: ValueError: need more

Re: iterating over list with one mising value

2012-02-07 Thread MRAB
On 07/02/2012 20:23, Sammy Danso wrote: Hi Expert, Thanks for your responses and help. thought I should provide more information for clarity. > Please find the error message below for more information for (key, value) in wordFreq2: ValueError: need more than 1 value to unpack this is a sam

Re: iterating over list with one mising value

2012-02-07 Thread Dave Angel
On 02/07/2012 03:23 PM, Sammy Danso wrote: Please don't top-post. It hopelessly mixes responses out of order. Hi Expert, Thanks for your responses and help. thought I should provide more information for clarity. Please find the error message below for more information for (key, value)

Re: iterating over list with one mising value

2012-02-07 Thread Sammy Danso
;, 1, 'difficulty', 1, 'cord', 1, 'consecutive', 1, 'colour', 1, 'cleared', 1, 'child', 1, 'checkups', 1, 'came', 1, 'but', 2, 'breathing', 2, 'breath', 1, 'blood', 2, 'blee

Re: iterating over list with one mising value

2012-02-07 Thread Tim Chase
On 02/07/12 09:34, Rick Johnson wrote: On Feb 7, 8:46 am, Dave Angel wrote: On 02/07/2012 07:27 AM, Sammy Danso wrote:> Hello experts, I am having trouble accessing the content of my list. my list content has 2-pair value with the exception of one which has single value. here is an example [

Re: iterating over list with one mising value

2012-02-07 Thread Ian Kelly
On Tue, Feb 7, 2012 at 5:27 AM, Sammy Danso wrote: > > Hello experts, > I am having trouble accessing the content of my list. > my list content has 2-pair value with the exception of one which has single > value. here is an example  ['a', 1, 'b', 1, 'c', 3, 'd'] > > I am unable to iterate through

Re: iterating over list with one mising value

2012-02-07 Thread Rick Johnson
On Feb 7, 8:46 am, Dave Angel wrote: > On 02/07/2012 07:27 AM, Sammy Danso wrote:> Hello experts, > > I am having trouble accessing the content of my list. > > my list content has 2-pair value with the exception of one which has single > > value. here is an example  ['a', 1, 'b', 1, 'c', 3, 'd']

Re: iterating over list with one mising value

2012-02-07 Thread Dave Angel
On 02/07/2012 07:27 AM, Sammy Danso wrote: Hello experts, I am having trouble accessing the content of my list. my list content has 2-pair value with the exception of one which has single value. here is an example ['a', 1, 'b', 1, 'c', 3, 'd'] I am unable to iterate through list to access in