names = list(('zss','jack','chenglong'))
print(names)
print(names[2])
names[2]='shy'
print(names)
print(names[1:2])
heros = ['阿轲','嬴政','韩信','露娜','后羿','亚瑟']
heros.append('猴子')
print(heros)
heros.insert(3,'李白')
print(heros)
x = ['特玛西亚','猫咪']
heros.extend(x)
print(heros)
masters = ['妲己','小乔','大乔']
x = masters.pop(1)
print(x)
print(masters)
masters.remove('大乔')
print(masters)
del masters[0]
print(masters)
masters.clear()
print(masters)
tanks = ['猴子','德玛','天使','张飞','程咬金','猴子']
tanks[1] = '凯'
print(tanks)
print(tanks.index('天使'))
print(tanks.count('猴子'))
print('天使' in tanks)
print('薇恩' in tanks)
killers = ['李白','兰陵王','韩信','赵云','阿轲','孙悟空']
for i in killers:
print(i)
i=0
while i < len(killers):
print(killers[i])
i += 1
a = 2
b = 3
a,b = b,a
print(a)
print(b)
nums = [6,5,3,1,8,7,2,4]
print(sorted(nums))
names = ['zss','shy','love']
names.reverse()
print(names)
x = [100,200,300]
y = x
z = x.copy()
x[0] = 1
print(y)
print(z)
import copy
a = copy.copy(x)
x = [100,200,300]
y = x[::]
x[0] = 1
print(y)
n=0
count=0
while n < len(nums):
i=0
flag = True
while i < len(nums) -1 - n:
count += 1
if nums[i] > nums[i+1]:
nums[i],nums[i+1] = nums[i+1],nums[i]
flag = False
i += 1
if flag:
break
n += 1
print(nums)
print(count)
nums = [3,23,4,667,8,9,0,234,123,123,45,23]
nums.sort()
print(nums[-1])
x = nums[0]
for num in nums:
if num > x:
x = num
print(x)
print(nums.index(x))
x = ['','','','','','','zss','shy']
x2 = []
for word in x:
if word != '':
x2.append(word)
print(x2)
import random
nums = [1,2,3,[100,233,2222],222]
teachers = ['a','b','c','d','e','f','g','h','i','j']
rooms = [[],[],[]]
for teacher in teachers:
room = random.choice(rooms)
room.append(teacher)
print(rooms)
for i,room in enumerate(rooms):
print('房间%d里一共有%d个老师,分别是:' % (i,len(room)),end='')
for teacher in room:
print(teacher,end=' ')
print()
nums = [i for i in range(10)]
print(nums)
nums = [i for i in range(10) if i % 2 == 0]
print(nums)
nums = [i for i in range(10) if i % 2 ]
print(nums)
x = []
for i in range(10):
if i % 2:
x.append(i)
points = [(x,y) for x in range(5,9) for y in range(10,20)]
print(points)
lis = [x for x in range(1,101)]
n = [lis[j:j+3] for j in range(0,100,3)]
print(n)
nums = [1,2,3,4,5]
num1 = nums
num2 = nums.copy()
num3 = copy.copy(nums)
import copy
words = ['hello','good',[100,200],'yes','hi','ok']
words1 = words.copy()
words2 = copy.deepcopy(words)
words[1] = 'zss'
print(words1)
words[2][0] = 1
print(words1)
print(words2)
words2[2][0] = 2
print(words2)
words = ['hello','yes','good']
nums = (1,23,5,6,7,8,2,5,6,7,8,98,7,6)
print(nums[3])
print(nums.index(5))
print(nums.count(6))
ages = (18,)
print(ages)
print(tuple('hello'))
print(tuple(words))
print(list(nums))
heights = ("189","174","170")
print('*'.join(heights))
print(''.join(('z','s','s')))
for i in nums:
print(i)
i = 0
while i < len(nums):
print(nums[i])
i += 1
person = {'name':'zss','age':24,'x':'y','addr':'SZ','pass':True,'love':['唱','跳','rap'],4:'good',('yes','no'):100}
print(person)
print(person['name'])
x = 'age'
print(person[x])
print(person['x'])
print(person.get('xx'))
print(person.get('xx','zsss'))
print(person.get('name','haha'))
print(person)
person['name'] = 'haha'
print(person)
person['gender'] = 'pople'
print(person)
person.pop('name')
print(person)
result = person.popitem()
print(result)
print(person)
del person['addr']
print(person)
person.clear()
print(person)
nums = [1,2]
nums1 = [3,4]
nums.extend(nums1)
print(nums)
print(nums + nums1)
word = (1,23)
wod1 = (33,222)
print(word + wod1)
person1 = {'name':'zss','age':24}
person2 = {'addr':'SZ','phone':888}
person1.update(person2)
print(person1)
person = {'name':'zss','age':24}
for x in person:
print(x,'=',person[x])
for k in person.keys():
print(k,'=',person[k])
for v in person.values():
print(v)
for item in person.items():
print(item[0],'=',item[1])
for k,v in person.items():
print(k,'=',v)
chars = ['a','c','s','s','a','g','w','a','t','t']
char_count = {}
for char in chars:
if char in char_count:
char_count[char] += 1
else:
char_count[char] = 1
print(char_count)
char_count = {}
for char in chars:
if char not in char_count:
char_count[char] = chars.count(char)
print(char_count)
for k,v in char_count.items():
if v == max(char_count.values()):
print(k)
persons = [{'name':'zss','age':24},{'name':'jack','age':22}]
dict1 = {"a":100,"b":200,"c":300}
dict2 = {}
for k,v in dict1.items():
dict2[v] = k
print(dict2)
dict1 = {v:k for k,v in dict1.items()}
print(dict1)