Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'one?': 0.05; 'suggestions.': 0.07; 'iterate': 0.09; 'truncate': 0.09; 'am,': 0.12; 'exception': 0.12; 'skips': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'problem?': 0.18; 'cc:no real name:2**0': 0.21; 'subject:list': 0.21; 'input': 0.22; 'header:In-Reply-To:1': 0.22; 'guess': 0.26; 'saying': 0.26; 'cc:2**0': 0.26; 'figure': 0.26; 'code,': 0.28; 'value.': 0.28; 'posted': 0.29; 'odd': 0.29; 'example': 0.29; 'cc:addr:python.org': 0.29; 'unable': 0.30; 'error': 0.30; 'actually': 0.31; 'device': 0.31; 'thanks': 0.32; 'list': 0.32; 'header:User-Agent:1': 0.33; 'it.': 0.33; 'appreciated.': 0.34; 'file': 0.34; 'loop': 0.34; 'size,': 0.34; 'stuck': 0.34; 'trouble': 0.35; 'list.': 0.35; 'list:': 0.35; 'run': 0.37; 'but': 0.37; 'subject:with': 0.37; 'received:192': 0.38; 'should': 0.38; 'data': 0.38; 'sometimes': 0.38; 'might': 0.40; 'more': 0.61; 'your': 0.61; 'here': 0.64; 'header:Reply- To:1': 0.70; 'reply-to:no real name:2**0': 0.72; 'subject:one': 0.77; 'to:addr:yahoo.com': 0.83; 'subject:over': 0.84; 'subject:value': 0.84 Date: Tue, 07 Feb 2012 09:46:12 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16 MIME-Version: 1.0 To: Sammy Danso Subject: Re: iterating over list with one mising value References: <1328617645.12769.YahooMailClassic@web161204.mail.bf1.yahoo.com> In-Reply-To: <1328617645.12769.YahooMailClassic@web161204.mail.bf1.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:wamuwALXeA6kRKnS+akgfPPfxEYOId1P61S2lnDiTBY SJd7r6fqiBIa9r7RfRPCUdSyf3tzN5z1tKw9Qi7ky2KO2eXllM fYL/Ey+skJSCVyovHQuGmVzmLj0dVgoZz1k4ozA9I7YystbOBx 9vcQDLFdRJgRcKdZythk1fg4qT1yzSb23J1axNWt4R6SHcvKqo 3n2WDECvakjvoTI7hndsGo9D/z78vCxxthbci05O7dQApYSf3u JUqJFwEuHNn+C9gvWETLEqSlxcYmsBW86ro8sgx/ESsm+iskM3 WK8CDdajlwU7spW1QPZsrQ2mcpC/WIMK5p83tmPFfEezk5tl41 0S7l0gbqjviG1c5k3n90= Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328625983 news.xs4all.nl 6960 [2001:888:2000:d::a6]:53196 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19960 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 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? > > Your help would be much appreciated. > > Thanks > Sammy The real answer is to figure out how it gets into that state. Is the input file invalid? Or you have a device that sometimes skips one? But if you're stuck with the data in that list: If the list is of odd size, truncate it. Then your loop should not run into an uneven pair. Of course if you actually posted the code, or even the real and complete error message, we might be able to make other suggestions. -- DaveA