In [1]:
l = [1,2,3,3,3,4,5,44]
In [2]:
s = set(l)
In [6]:
s.intersection([33,44,1,1])
Out[6]:
In [8]:
s.union([111,2,3])
Out[8]:
nie można indeksować zbioru
In [10]:
s[1]
ale można iterować po jego elementach
In [11]:
for el in s:
print(el)
In [14]:
l = [13,2,3,4]
In [15]:
sorted(l)
Out[15]:
In [16]:
l
Out[16]:
In [17]:
l.sort()
In [18]:
l
Out[18]:
In [19]:
l.sort(key=lambda x:1/x)
In [20]:
l
Out[20]:
In [21]:
def f(x):
return 1/x
In [22]:
l.sort(key=f)
In [23]:
l
Out[23]:
In [33]:
l = [("a",1),(2,3),(-1,3)]
l
Out[33]:
In [34]:
def f(x):
return x[1]
In [32]:
l.sort()
In [35]:
l.sort(key=f)
In [36]:
l
Out[36]:
In [47]:
l = [ (x,y) for x in range(44) for y in range(44) ]
In [48]:
def f(X):
return( X[0]**2+ X[1]**2)
In [49]:
l.sort(key=f)
In [50]:
%matplotlib inline
import matplotlib.pyplot as plt
In [54]:
l1 = l
plt.plot([x_[0] for x_ in l1],[x_[1] for x_ in l1],'o')
l1 = l[:230]
plt.plot([x_[0] for x_ in l1],[x_[1] for x_ in l1],'or')
Out[54]:
In [86]:
l = [1,2,3,4,5]
k = -1
In [87]:
l[:-k]
Out[87]:
In [88]:
l[-k:]
Out[88]:
In [89]:
l[-k:]+l[:-k]
Out[89]:
In [ ]:
In [ ]: