Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'transform': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'entries': 0.15; '1),': 0.16; '3),': 0.16; 'bieber': 0.16; 'email addr:ix.netcom.com': 0.16; 'email name:wlfraed': 0.16; 'from:addr:ix.netcom.com': 0.16; 'from:addr:wlfraed': 0.16; 'from:name:dennis lee bieber': 0.16; 'message-id:@4ax.com': 0.16; 'received:wlfraed': 0.16; 'unpacking': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'wulfraed': 0.16; 'this:': 0.16; 'wrote:': 0.18; 'received:166': 0.18; 'url:home': 0.21; 'subject:list': 0.21; 'feb': 0.22; 'modify': 0.25; 'load': 0.26; 'work.': 0.27; 'work,': 0.28; 'fails.': 0.30; 'does': 0.32; 'tue,': 0.32; 'list': 0.32; 'file': 0.34; 'header:X-Complaints-To:1': 0.34; 'lee': 0.34; 'to:addr:python-list': 0.35; 'something': 0.35; 'received:org': 0.36; 'charset:us-ascii': 0.37; 'subject:with': 0.37; 'correctly': 0.39; 'fail': 0.39; 'to:addr:python.org': 0.40; 'more': 0.61; 'your': 0.61; 'dennis': 0.73; 'subject:one': 0.77; 'subject:over': 0.84; 'subject:value': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: iterating over list with one mising value Date: Tue, 07 Feb 2012 17:57:37 -0500 References: <1328646189.84221.YahooMailClassic@web161206.mail.bf1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: mobile-166-147-103-041.mycingular.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328655612 news.xs4all.nl 6909 [2001:888:2000:d::a6]:44577 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19990 On Tue, 7 Feb 2012 21:37:20 +0000, 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)] > >Then it will work. The quickest way to transform your list to the >required form is something like this: > Well... From my viewpoint, the quickest way is to load the list correctly in the first place... Where does this list come from? If it's a file of word count pairs, then wordFreq2 = [] for ln in inputFile: (word, freq) = ln.strip().split() #any line with more or less than #2 entries will fail wordFreq2.append( (word, int(freq)) ) Modify as needed if the file is word count ... -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/