Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.036 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'iterate': 0.09; 'received :mail-lpp01m010-f46.google.com': 0.09; 'recipe': 0.09; 'am,': 0.12; 'exception': 0.12; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'problem?': 0.18; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'subject:list': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'guess': 0.26; 'saying': 0.26; 'cc:2**0': 0.26; 'value.': 0.28; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.29; 'unable': 0.30; 'error': 0.30; 'url:library': 0.31; 'received:209.85.215.46': 0.32; 'tue,': 0.32; 'list': 0.32; 'instead': 0.33; 'trouble': 0.35; 'list.': 0.35; 'url:python': 0.35; 'received:google.com': 0.37; 'using': 0.37; 'subject:with': 0.37; 'received:209.85': 0.38; 'should': 0.38; 'url:org': 0.39; 'received:209.85.215': 0.39; 'received:209': 0.39; 'more': 0.61; 'here': 0.64; 'subject:one': 0.77; 'to:addr:yahoo.com': 0.83; 'subject:over': 0.84; 'subject:value': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=G9Q5F8grlJGOzv03m6vnT/2XQejkHGx6jI2V9DKRneo=; b=rxqetrGOUOnlx6PdpybmxK5K77rm5VgFHmqBv9LSqO2NNRsw/c96BVHYlIo9CzITYt XICoaMeHldzAZHGFaHwZO0CwKJj0M3XhvvQQPq2n0lzmtyWJfx7Q6rrIpr9rs4GKwAZi 4I3tzwWmCzXcUDA8wibqpkypxskPnQQN9n3nY= MIME-Version: 1.0 In-Reply-To: <1328617645.12769.YahooMailClassic@web161204.mail.bf1.yahoo.com> References: <1328617645.12769.YahooMailClassic@web161204.mail.bf1.yahoo.com> From: Ian Kelly Date: Tue, 7 Feb 2012 09:03:52 -0700 Subject: Re: iterating over list with one mising value To: Sammy Danso Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328630667 news.xs4all.nl 6856 [2001:888:2000:d::a6]:39354 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19965 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 sing= le value. here is an example=A0 ['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