Last active
June 4, 2016 21:04
-
-
Save h3xh4wk/5611724 to your computer and use it in GitHub Desktop.
python list comprehensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# search elements of one list in another list without nested loops | |
tosearch = ['x','z',10] | |
tobesearched = ['x','y',1,2,3] | |
found = [item | |
for item in tosearch | |
for item2 in tobesearched if item == item2] | |
print found |
it worked for searching the lists too
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMO, we should use this only when the lists to loop are really not that big.