Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19965

Re: iterating over list with one mising value

References <1328617645.12769.YahooMailClassic@web161204.mail.bf1.yahoo.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-02-07 09:03 -0700
Subject Re: iterating over list with one mising value
Newsgroups comp.lang.python
Message-ID <mailman.5503.1328630667.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Feb 7, 2012 at 5:27 AM, Sammy Danso <samdansobe@yahoo.com> 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 invidual value pairs
>
> I get an error message saying ' the list should more than 1 value pairs'. I guess because 'd' has no value. How do I solve this problem?

What are you using to iterate through pairs instead of individual
elements?  It sounds like it is not very flexible.  I would recommend
instead using the "grouper" recipe from the itertools documentation:

http://docs.python.org/library/itertools.html#recipes

Cheers,
Ian

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: iterating over list with one mising value Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-07 09:03 -0700
  Re: iterating over list with one mising value Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-08 01:50 +0000

csiph-web