473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

TypeError: 'int' object is not iterable

Expand|Select|Wrap|Line Numbers
  1. def remove_duplicates(xlist):
  2.     new_list = []
  3.     return [x*y for x,y in xlist if y not in new_list.iteritems()]
  4.  
  5. print remove_duplicates([4,5,5,6])
i am trying to remove repeating numbers from a list that can be any size. but when I test out this idea i hit a brick wall. I get TypeError: 'int' object is not iterable. I have tried several alternatives as a single liner but was unsuccessful. Please can somone help me.
Jan 8 '14 #1
1 11460
bvdet
2,851 Expert Mod 2GB
What end result are you looking for? The code segment for x,y in [1,2,3,4] will always fail.
Expand|Select|Wrap|Line Numbers
  1. >>> for x,y in [1,2]:
  2. ...     print x,y
  3. ...     
  4. Traceback (most recent call last):
  5.   File "<interactive input>", line 1, in <module>
  6. TypeError: 'int' object is not iterable
  7. >>> 
If you want to remove duplicates from xlist and keep the order of the sequence:
Expand|Select|Wrap|Line Numbers
  1. >>> output = []
  2. >>> xlist = [1,2,3,5,5,5,6,6,7,8,8]
  3. >>> for item in xlist:
  4. ...     if item not in output:
  5. ...         output.append(item)
  6. ...         
  7. >>> output
  8. [1, 2, 3, 5, 6, 7, 8]
  9. >>> 
Are you trying to do this?
Expand|Select|Wrap|Line Numbers
  1. >>> output
  2. [1, 2, 3, 5, 6, 7, 8]
  3. >>> reduce(lambda x,y: x*y, output)
  4. 10080
  5. >>> 
Jan 8 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Balaji | last post by:
Hello Everybody... I have a problem.. This is the code... -------------------------------------- class Stack: def __init__(self,expr): self.stackP=
2
by: AWasilenko | last post by:
I'm trying to test a few different approaches to displaying pages via Cherrypy and I'm not having much luck. Here is my code so far: import sys, cherrypy, html class Root: @cherrypy.expose...
0
by: king kikapu | last post by:
Hi, i have a problem with the following piece of code that id just drive me nuts (from the morning...) I think is more Python specific than Qt, folks from Qt forum have already give me...
33
by: christophertidy | last post by:
Hi I am new to Python and have recieved this error message when trying to instantiate an object from a class from another file within the same directory and wondered what I have done wrong. I...
19
by: python101 | last post by:
I try to calculate the sum of an infinite series S = Sum (from n=0 to 100) 1/k! I got message 'float' / 'int' object is not iterable. How can I fix this?
2
by: mmiikkee13 | last post by:
>>a_list = range(37) .... 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...
1
by: mankeluvsit | last post by:
hey everyone, for reasons, i needed to grap information from steampowered.com from BeautifulSoup import BeautifulSoup from urllib import urlopen import re import codecs html_text =...
3
bferguson94
by: bferguson94 | last post by:
I think this program should work, but for some reason i keep getting a "TypeError: 'function' object is not iterable which is keeping my program from accesing the text document.. any suggestions?...
1
by: Gonzalo Gonza | last post by:
When I execute this code (if the number finishes in 2 returns true, else none) def asdf(n): n=str(m) elif m==2: return True I get the following Error: Traceback (most recent call...
3
by: Barry1point4 | last post by:
I've been learing python from http://www.learnpython.org/page/Functions and in the functions lesson I've got stuck on the exercise for 2 days now. As far as I can tell my code should work but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.