Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19990 > unrolled thread
| Started by | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| First post | 2012-02-07 17:57 -0500 |
| Last post | 2012-02-07 17:57 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: iterating over list with one mising value Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-02-07 17:57 -0500
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-02-07 17:57 -0500 |
| Subject | Re: iterating over list with one mising value |
| Message-ID | <mailman.5521.1328655612.27778.python-list@python.org> |
On Tue, 7 Feb 2012 21:37:20 +0000, Arnaud Delobelle <arnodel@gmail.com>
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/
Back to top | Article view | comp.lang.python
csiph-web