Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.056 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'iterate': 0.09; 'stack.': 0.09; 'valueerror:': 0.09; 'exception': 0.12; 'processed': 0.15; "'',": 0.16; '(key,': 0.16; 'pad': 0.16; 'unpack': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.18; 'help.': 0.19; 'subject:list': 0.21; 'header:In-Reply-To:1': 0.22; 'end,': 0.23; 'guess': 0.26; 'code': 0.26; 'cc:addr:gmail.com': 0.28; 'order.': 0.28; "skip:' 10": 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'value)': 0.30; 'error': 0.30; 'file.': 0.31; 'good.': 0.32; 'thanks': 0.32; 'list': 0.32; 'header:User-Agent:1': 0.33; 'end.': 0.34; 'cc:2**1': 0.36; 'but': 0.37; 'subject:with': 0.37; 'enough': 0.38; 'received:192': 0.38; 'format': 0.38; 'getting': 0.38; 'should': 0.38; 'data': 0.38; 'ok,': 0.39; 'entirely': 0.40; 'missing': 0.40; 'more': 0.61; 'your': 0.61; 'you.': 0.62; 'below': 0.62; 'show': 0.66; '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 15:58:25 -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: <1328646189.84221.YahooMailClassic@web161206.mail.bf1.yahoo.com> In-Reply-To: <1328646189.84221.YahooMailClassic@web161206.mail.bf1.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:UYeCmxM0WNbvhg6X3F7ZQWZ2kFimjaCj0OQHx7k/meM WM3WP/XZCdak7XzLOQFef2u6Z1wTmFtqZjWEGHmnh8ypRPf87l uiFKYYAfURVreki2ivu3yd2tKyeRN5GdoO2Rl0hnh46/zvi/AT rlcf6RANQNz915aSZ9HDbflvHsoRU3bY/mBKYjGR8cDaLiC2kj 7njyiDQLUn0C6qmwPRbccqxbaONd5mN15h+6+EvcnOK9+jJqDU Pvy0y5DpS3qsTysrPDkg4OxBH9NQXhx6oul48Sv8XhKn54LgB3 5KPb2EEBMHIl1uY/NCpgB6+VuHebWvfPyY9/545T7mpbCLdOAA fy0cSgYhDo0U9VDwVuTI= 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: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328648323 news.xs4all.nl 6979 [2001:888:2000:d::a6]:41208 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19982 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) in wordFreq2: > ValueError: need more than 1 value to unpack That's not the complete error message; it's missing the call stack. And also missing the line that's getting the ValueError. > > this is a sample of my data > > ['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', 1, 'respectively', 1, 'received', 1, 'problems', 2, 'prince', 1, 'pregnancy', 1, 'poured', 1, 'peace', 1, 'pains', 1, 'painless', 1, 'out', 1, 'of', 1, 'noseat', 1, 'nose', 2, 'no', 2, 'maternity', 1, 'malformation', 1, 'made', 1, 'lower', 1, 'labour/delivery', 2, 'kintampo', 1, 'into', 1, 'injections', 1, 'in', 3, 'i', 2, 'hospital', 1, 'home', 1, 'him', 1, 'having', 1, 'had', 2, 'green', 1, 'gave', 1, 'flowing', 2, 'encountered', 1, 'eleven', 1, 'during', 3, 'district', 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, 'bleeding', 1, 'birth', 4, 'before', 1, 'bad', 1, 'average', 1, 'at', 2, 'assist', 1, 'artificial', 1, 'around', 2, 'antenatal', > 1, 'and', 5, 'an', 1, 'ambrical', 1, 'air', 1, 'abdominal', 1, '600am', 1, '100pm', 1, '', 3, 'other'] > > What I would like to do is to pad the last value 'other' with a default so I can iterate sucessfully OK, good. If you know your error is always at the end, and you know the data to be padded, then just do it: if len(mylist) % 2 > 0: mylist.append(0) > > my desired ouput is the format below in a text file. > with 3 > which 3 > were 2 > .. > . > . > other > > > Thanks again. > Sammy My guess is that you have an entirely different problem, unrelated to the missing value at the end. But you don't show us enough code to help you. How many items of the list are processed before the exception happens? -- DaveA