[Tutor] nested loops
Kent Johnson
kent37 at tds.net
Mon Aug 22 13:11:30 CEST 2005
Jonas Melian wrote:
> Is there any way more efficient for run a nested loop?
>
> ------
> for a in list_a:
> for b in list_b:
> if a == b: break
efficient in running time? lines of code? What you have is pretty simple, what don't you like about it?
In Python 2.4 you could use a generator expression:
for (a for a in list_a for b in list_b if a==b):
break
If you want to know which is faster you have to time them...
Kent
More information about the Tutor
mailing list