Skip to content

Instantly share code, notes, and snippets.

@savish
Last active April 11, 2017 13:46
Show Gist options
  • Save savish/e25a9117dbc4dec19f01fa419c389bcc to your computer and use it in GitHub Desktop.
Save savish/e25a9117dbc4dec19f01fa419c389bcc to your computer and use it in GitHub Desktop.
List matrix thingy
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