Last active
April 11, 2017 13:46
-
-
Save savish/e25a9117dbc4dec19f01fa419c389bcc to your computer and use it in GitHub Desktop.
List matrix thingy
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
vals = [1,2,3] | |
def afunc(v1, v2): | |
return v1 * v2 | |
for k in vals: | |
for j in vals: | |
print(afunc(k, j)) | |
# Result | |
1 | |
2 | |
3 | |
2 | |
4 | |
6 | |
3 | |
6 | |
9 | |
# One-liner | |
print ([afunc(x, y) for x in vals for y in vals]) | |
# Result | |
[1, 2, 3, 2, 4, 6, 3, 6, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment