>>a_list = range(37)
>>list_as_dict = dict(zip(range(len(a_list)), [str(i) for i in a_list])) for k, v in list_as_dict:
.... print k, v
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
What 'int' object is this referring to? I'm iterating over a dict, not
an int. 2 10961
On Oct 5, 8:11*pm, mmiikkee13 <mmiikke...@gmail.comwrote:
>a_list = range(37) list_as_dict = dict(zip(range(len(a_list)), [str(i) for i in a_list])) for k, v in list_as_dict:
... * * print k, v
...
Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
What 'int' object is this referring to? I'm iterating over a dict, not
an int.
It thinks you are trying to unpack the first item, you mean to be
doing for k, v in list_as_dict.iteritems()
mmiikkee13 schrieb:
>>>a_list = range(37) list_as_dict = dict(zip(range(len(a_list)), [str(i) for i in a_list])) for k, v in list_as_dict:
... print k, v
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
What 'int' object is this referring to? I'm iterating over a dict, not
an int.
Because
for name in dictionary:
will bind name to the *keys* of dictionary. Thus you end up with an int.
Then the tuple-unpacking occurs:
k, v = <number>
Which is equivalent to
k = <number>[0]
v = <number>[1]
And because <numberisn't iterable, it will fail.
Use
for k, v in dictionary.iteritems():
instead.
Diez This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ajax Chelsea |
last post by:
can not the "static const int" be replaced by "static enum" anywhere?
is it necessary that define special initialization syntax for "static const int"?
|
by: Matt |
last post by:
I want to know if "int" is a primitive type, or an object?
For example, the following two approaches yield the same result.
> int t1 = int.Parse(TextBox2.Text); //method 1
> int t2 =...
|
by: jacob navia |
last post by:
Hi
Suppose you have somewhere
#define BOOL int
and somewhere else
typedef BOOL int;
|
by: Juha Nieminen |
last post by:
Consider this code:
void foo(int& i)
{
i += 10;
}
int main()
{
int a = 1;
|
by: Lawrence Spector |
last post by:
I ran into a problem using g++. Visual Studio 2005 never complained
about this, but with g++ I ran into this error. I can't figure out if
I've done something wrong or if this is a compiler bug. ...
|
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= |
last post by:
I get the above error in some of the ASP.NET web applications on a
server, and I need some help figuring out how to deal with it.
This is a rather long post, and I hope I have enough details that...
|
by: =?GB2312?B?zPC5zw==?= |
last post by:
Howdy,
I wonder why below does not work.
a = object()
a.b = 1 # dynamic bind attribute failed...
To make it correct, we have to create a new class:
class MyClass(object): pass
a =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |