In [1]:
import sympy as sym
import numpy as np
from IPython.display import display, Math
from sympy.abc import w,x,y,z,a,b,c,d
sym.init_printing()
In [2]:
lst = [1,3,6,7,1,3,6,7,1,3,6,7,1,3,6,7,1,3,6,7]
lst
Out[2]:
$$\left [ 1, \quad 3, \quad 6, \quad 7, \quad 1, \quad 3, \quad 6, \quad 7, \quad 1, \quad 3, \quad 6, \quad 7, \quad 1, \quad 3, \quad 6, \quad 7, \quad 1, \quad 3, \quad 6, \quad 7\right ]$$
In [3]:
type(lst)
Out[3]:
list
In [4]:
lst[3]
Out[4]:
$$7$$
In [5]:
# slicing
N = 2
lst[:N]
Out[5]:
$$\left [ 1, \quad 3\right ]$$
In [6]:
K = 2
lst[-K:]
Out[6]:
$$\left [ 6, \quad 7\right ]$$
In [7]:
n = 3
k = 7

print(lst)
lst[n:k]
[1, 3, 6, 7, 1, 3, 6, 7, 1, 3, 6, 7, 1, 3, 6, 7, 1, 3, 6, 7]
Out[7]:
$$\left [ 7, \quad 1, \quad 3, \quad 6\right ]$$
In [8]:
words = ['hello', 'my', 'name', 'is', 'Mike']

for i in range(0,len(words)):
    print (words[i])
hello
my
name
is
Mike
In [9]:
alist = [1,2,'cookies',[6,4]]
for i in alist:
    print(i)
1
2
cookies
[6, 4]
In [10]:
alist[-1][1]
Out[10]:
$$4$$
In [11]:
e1 = 2*x+x*(4-6*x)+x
e2 = -x*(2/x+4/x**2) + (4+x)/(4*x)
e3 = (x+3)*(x-3)*x*(1/(9*x))

exprs = [e1,e2,e3]

for i in exprs:
    display(Math('%s \\quad \\Longleftrightarrow \\quad %s' %(sym.latex(i),sym.latex(sym.expand(i)))))
$\displaystyle x \left(- 6 x + 4\right) + 3 x \quad \Longleftrightarrow \quad - 6 x^{2} + 7 x$
$\displaystyle - x \left(\frac{2}{x} + \frac{4}{x^{2}}\right) + \frac{x + 4}{4 x} \quad \Longleftrightarrow \quad - \frac{7}{4} - \frac{3}{x}$
$\displaystyle \frac{1}{9} \left(x - 3\right) \left(x + 3\right) \quad \Longleftrightarrow \quad \frac{x^{2}}{9} - 1$