Skip to content

Instantly share code, notes, and snippets.

@tjhartline
Created June 8, 2022 04:23
Show Gist options
  • Save tjhartline/1577501ba477286cd579ab78cdf7d970 to your computer and use it in GitHub Desktop.
Save tjhartline/1577501ba477286cd579ab78cdf7d970 to your computer and use it in GitHub Desktop.
Multiplication list in python
user_input= input()
lines = user_input.split(',')
# This line uses a construct called a list comprehension, introduced elsewhere,
# to convert the input string into a two-dimensional list.
# Ex: 1 2, 2 4 is converted to [ [1, 2], [2, 4] ]
mult_table = [[int(num) for num in line.split()] for line in lines]
for row in mult_table:
print(" | ".join([str(cell) for cell in row]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment