In [1]:
def n_divide(n):
L = []
for i in range(n+1):
L.append(i * 1.0/n)
return L
n_divide(10)
Out[1]:
In [2]:
def sen2word(xs):
for i in xs.split():
print(i)
sen2word("I am learning Python. It's quite interesting.")
In [3]:
def fibo(n):
F = [1, 1]
for i in range(2, n):
F.append(F[i-1] + F[i-2])
return F
print(fibo(10))
In [4]:
fibo(5)
Out[4]:
In [5]:
def second(t):
return t[1]
def sort_notes(xs):
xs.sort(key=second, reverse=True)
return xs
L = [("Lee", 45), ("Kim", 30), ("Kang", 70), ("Park", 99), ("Cho", 65)]
sort_notes(L)
Out[5]:
In [6]:
def num_sum(xs):
L = []
for i in xs:
if isinstance(i, int) or isinstance(i, float):
L.append(i)
else:
pass
return sum(L)
L = [5, 'abc', 2, [2,3]]
num_sum(L)
Out[6]:
In [7]:
L
Out[7]: