######################## P20
list=[1,2,3,'aaaa']
print(list)
for each in list:
print(each)
list_len=len(list)
print(list[list_len-1])
print(list[-1])
print(list[2:3])
print(list[2:])
print(list[:2])
print(list[0:3:2])
######################## P21
heros=['钢铁侠','绿巨人']
heros.append('黑寡妇')
heros.extend(['鹰眼','灭霸'])
s=[1,2,3,4,5]
s[len(s):] = [7,8,9]
print(s)
s=[1,3,4,5]
s.insert(1,2)
s.insert(0,0)
s.insert(len(s),6)
print(s)
heros.remove('灭霸')
heros.pop(2)
heros.clear()
print(heros)
######################## P22
heros=['蜘蛛侠','绿巨人','黑寡妇','鹰眼','灭霸','雷神']
heros[0]='钢铁侠'
heros[3:]=['武松','林冲','李逵']
print(heros)
nums=[3,1,9,6,8,3,5,3]
nums.sort()
nums.reverse()
print(nums)
nums=[3,1,9,6,8,3,5,3]
nums.sort(reverse=True)
print(nums)
nums_3=nums.count(3)
print(nums_3)
heros_lv=heros.index("绿巨人")
print(heros_lv)
heros[heros.index("绿巨人")]='神奇女侠'
print(heros)
nums=[3,1,9,6,8,3,5,3]
nums_index_3=nums.index(3,1,7)
print(nums_index_3)
nums_copy1=nums.copy()
nums_copy2=nums[:]
######################## P23
s=[1,2,3]
t=[4,5,6]
st=s+t
s3=s*3
print(st)
print(s3)
matrix=[[1,2,3],
[4,5,6],
[7,8,9]]
for i in matrix:
print(i)
for each in i:
print(each,end=' ')
print()
print(matrix[0][0])
A=[0]*3
for i in range(3):
A[i]=[0]*3
B=[[0]*3]*3
A[1][1]=1
B[1][1]=1
print(A)
print(B)
x='cccc'
y='cccc'
xy=(x is y)
print(xy)
x=[1,2,3]
y=[1,2,3]
xy=(x is y)
print(xy)
######################## P24
x=[1,2,3]
y=x
x[1]=1
print(x)
print(y)
x=[1,2,3]
y=x.copy()
x[1]=1
print(x)
print(y)
x=[1,2,3]
y=x[:]
x[1]=1
print(x)
print(y)
x=[[1,2,3],
[4,5,6],
[7,8,9]]
y=x.copy()
x[1][1] =0
print(x)
print(y)
import copy
x=[[1,2,3],
[4,5,6],
[7,8,9]]
y=copy.deepcopy(x)
x[1][1] =0
print(x)
print(y)
######################## P25
oho=[1,2,3,4,5]
for i in range(len(oho)):
oho[i]=oho[i]*2
print(oho)
oho=[1,2,3,4,5]
oho=[i*2 for i in oho]
print(oho)
x=[i+1 for i in range(10) ]
print(x)
y=[c*2 for c in 'FishC']
print(y)
code=[ord(c) for c in 'FishC']
print(code)
matrix=[[1,2,3],
[4,5,6],
[7,8,9]]
col2=[row[1] for row in matrix]
print(col2)
diag=[matrix[i][i] for i in range(len(matrix))]
print(diag)
diag=[matrix[i][len(matrix)-1-i] for i in range(len(matrix))]
print(diag)
######################## P26
B=[[0]*3] *3
B[1][1] =1
print(B)
A=[0]*3
for i in range(3):
A[i]=[0]*3
A[1][1] =1
print(A)
s=[[0]*3 for i in range(4)]
print(s)
even=[i for i in range(10) if i%2==0 ]
print(even)
even=[i+1 for i in range(10) if i%2==0 ]
print(even)
words=['Great','FishC','Brilliant','Excellent','Fantistic']
word_F=[i for i in words if i[0]=='F' ]
print(word_F)
matrix=[[1,2,3],
[4,5,6],
[7,8,9]]
flatten=[col for row in matrix
for col in row]
print(flatten)
flatten=[]
for row in matrix:
for col in row:
flatten.append(col)
print('s',flatten)
z=[x+y for x in 'fishc'
for y in 'FISHC']
print(z)
z=[[x,y] for x in range(10) if x%2==0
for y in range(10) if y%3==0]
print(z)
z=[]
for x in range(10):
if x%2 ==0:
for y in range(10):
if y%3==0:
z.append([x,y])
print('w',z)