In [2]:
a = 'abc'
b = 'def'

In [5]:
for s in 'a':
    print(s)


a

In [12]:
for s in a:
    for t in b:
        print(s+t)


ad
ae
af
bd
be
bf
cd
ce
cf

In [13]:
final=[]
for s in a:
    for t in b:
        final.append(s+t)
print(final)


['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf']

In [15]:
[s for s in a]


Out[15]:
['a', 'b', 'c']

In [16]:
[s+t for s in a for t in b]


Out[16]:
['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf']

Create Grid


In [25]:
def cross(a, b):
    return [s+t for s in a for t in b]

In [21]:
rows = 'ABCDEFGHI'
cols = '123456789'

In [27]:
boxes = cross(rows, cols)
print(boxes)


['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'I9']

In [32]:
row_units = [cross(r, cols) for r in rows]

In [37]:
column_units = [cross(rows, c) for c in cols]

In [39]:
square_units = [cross(rs, cs) for rs in ('ABC','DEF','GHI') for cs in ('123','456','789')]

In [42]:
unitlist = row_units + column_units + square_units
print(unitlist)


[['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9'], ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9'], ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'], ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9'], ['E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9'], ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9'], ['G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9'], ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9'], ['I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'I9'], ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1'], ['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2'], ['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3'], ['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4'], ['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5'], ['A6', 'B6', 'C6', 'D6', 'E6', 'F6', 'G6', 'H6', 'I6'], ['A7', 'B7', 'C7', 'D7', 'E7', 'F7', 'G7', 'H7', 'I7'], ['A8', 'B8', 'C8', 'D8', 'E8', 'F8', 'G8', 'H8', 'I8'], ['A9', 'B9', 'C9', 'D9', 'E9', 'F9', 'G9', 'H9', 'I9'], ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3'], ['A4', 'A5', 'A6', 'B4', 'B5', 'B6', 'C4', 'C5', 'C6'], ['A7', 'A8', 'A9', 'B7', 'B8', 'B9', 'C7', 'C8', 'C9'], ['D1', 'D2', 'D3', 'E1', 'E2', 'E3', 'F1', 'F2', 'F3'], ['D4', 'D5', 'D6', 'E4', 'E5', 'E6', 'F4', 'F5', 'F6'], ['D7', 'D8', 'D9', 'E7', 'E8', 'E9', 'F7', 'F8', 'F9'], ['G1', 'G2', 'G3', 'H1', 'H2', 'H3', 'I1', 'I2', 'I3'], ['G4', 'G5', 'G6', 'H4', 'H5', 'H6', 'I4', 'I5', 'I6'], ['G7', 'G8', 'G9', 'H7', 'H8', 'H9', 'I7', 'I8', 'I9']]

In [59]:
for row in row_units:
    print(' | '.join(row))


A1 | A2 | A3 | A4 | A5 | A6 | A7 | A8 | A9
B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B9
C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9
D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9
E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9
F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9
G1 | G2 | G3 | G4 | G5 | G6 | G7 | G8 | G9
H1 | H2 | H3 | H4 | H5 | H6 | H7 | H8 | H9
I1 | I2 | I3 | I4 | I5 | I6 | I7 | I8 | I9


In [65]:
0.000001 * 10**6


Out[65]:
1.0

In [67]:
n = 10**9
for i in range(10**6):
    n += 0.000001
print(n-10**9)


0.95367431640625

In [69]:
r = 106 
g = 252
b = 39

print((106-128)/128)
print((252-128)/128)
print((39-128)/128)


-0.171875
0.96875
-0.6953125

In [102]:
def moveX(d, l):
    x = l[0]
    y = l[1]
    return (d + x, y)

s = (0,0)

moveX(3, s)


Out[102]:
(3, 0)

In [104]:
import math
math.sqrt(4)


Out[104]:
2.0

In [ ]: