Dictionary error

John Gordon gordon at panix.com
Tue Nov 25 17:36:05 CET 2014

In <mailman.16275.1416914234.18130.python-list at python.org> Thuruv V <wasp52dex at 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 at panix.com    watch 'House', or a real serial killer to watch 'Dexter'.

More information about the Python-list mailing list