Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81520

Re: Dictionary error

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!ra.nrl.navy.mil!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!gordon
From John Gordon <gordon@panix.com>
Newsgroups comp.lang.python
Subject Re: Dictionary error
Date Tue, 25 Nov 2014 16:36:05 +0000 (UTC)
Organization PANIX Public Access Internet and UNIX, NYC
Lines 39
Message-ID <m52b5l$koh$1@reader1.panix.com> (permalink)
References <mailman.16275.1416914234.18130.python-list@python.org>
NNTP-Posting-Host panix1.panix.com
X-Trace reader1.panix.com 1416933365 21265 166.84.1.1 (25 Nov 2014 16:36:05 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Tue, 25 Nov 2014 16:36:05 +0000 (UTC)
User-Agent nn/6.7.3
Xref csiph.com comp.lang.python:81520

Show key headers only | View raw


In <mailman.16275.1416914234.18130.python-list@python.org> Thuruv V <wasp52dex@gmail.com> writes:

> Please Clarify the 'TypeError: zip argument #1 must support iteration'


> import openpyxl

> book = openpyxl.load_workbook('c:/users/c_thv/desktop/tax.xlsx')
> sheet = book.get_sheet_by_name('Thilip')
> cell = sheet.cell(row=2,column = 4)
> i = 2
> x = []
> y = []while i < 10:
>    keys = sheet.cell(row=i,column = 4)
>    values = sheet.cell(row = i,column = 5)
>    x.append(keys.value)
>    y.append(values.value)
>    i +=1
>    mydict = dict(zip(keys,values)print mydict

The purpose of zip() is to accept two (or more) sequences and return a
single sequence with the corresponding members of the input sequences
paired together.

For example, if you had a list of names and a list of ages, calling zip
on the two lists would produce single list of (name, age) pairs.

But you're calling zip on two single items, not sequences, and you
can't do that.

Glancing over the code it appears that you're saving the cell contents
in two lists, x and y.  Perhaps you meant to call zip on those lists
instead of on keys and values?

-- 
John Gordon         Imagine what it must be like for a real medical doctor to
gordon@panix.com    watch 'House', or a real serial killer to watch 'Dexter'.

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Dictionary error Thuruv V <wasp52dex@gmail.com> - 2014-11-25 15:04 +0530
  Re: Dictionary error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-25 22:30 +1100
  Re: Dictionary error John Gordon <gordon@panix.com> - 2014-11-25 16:36 +0000

csiph-web