On Wed, Nov 18, 2009 at 1:51 PM, GoodPotatoes <goodpotat...@yahoo.com> wrote: > I'm dealing with bigger lists than I have been, and noticed this is getting > really slow. Is there a faster way to do this? > > for x in list1: > if x not in list2: > list3.append(x) > > My search is taking up to 5 minutes to complete.
greetings! hopefully this isn't a homework problem as we cannot help with those. can you give us an example of the lists that you're using (not the entire things, but just tell us what they contain)? also, use the timeit module to show us some numbers to confirm what you're seeing. my suggestion would be to use sets if possible instead of lists since those lookups are way faster (hash vs. sequence). if you're using Python 3, i think you can even build the solution set using set comprehensions. -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor