In [1]:
addition_problems_and_answers = [
('11 + 11', '22'),
('11 + 2', '13'),
('11 + 3', '14'),
]
good = addition_problems_and_answers
good
Out[1]:
In [2]:
addition_problems_and_answers = '''
11 + 11, 22
11 + 2, 13
11 + 3, 14
'''
a = addition_problems_and_answers
b = [
tuple(term.strip() for term in line.split(','))
for line in a.split('\n')
if line.strip()
]
b
Out[2]:
In [3]:
from random import choice, choices
In [4]:
for _ in range(10):
print(choice(b))
In [5]:
choices(b, k=10)
Out[5]:
In [6]:
print('hello', 'world')
In [7]:
addition_problems_text = '''
11 11
11 2
11 3
'''
a = addition_problems_text
b = [
tuple(operand.strip() for operand in line.split())
for line in a.split('\n')
if line.strip()
]
b
Out[7]:
In [8]:
a.split('\n')
Out[8]:
In [9]:
a.strip().split('\n')
Out[9]:
In [10]:
addition_problems_text = '''
11 11
11 2
11 3
'''
a = addition_problems_text
b = [
tuple(int(operand.strip()) for operand in line.split())
for line in a.split('\n')
if line.strip()
]
b
Out[10]:
In [11]:
actions = {
'add': 1,
'subtract': 'hello',
'stats': int,
'quit': 1j,
}
In [12]:
choices = ' or '.join(f'"{action}"' for action in actions)
print(f'Please type {choices}. ')
In [13]:
choices = ' or '.join(map(lambda action: f'"{action}"', actions))
print(f'Please type {choices}. ')