You are on page 1of 3

Tên: Tống Võ Trường Thịnh

Lớp DCT120C3
MSSV: 3120411148

LIST
B)
1)
A = ["3","27","5","123","9","1"]
A.sort(key=str)
print(A)
A.sort(key=int)
print(A)
2)
list = [12,24,35,70,88,120,155]
index_remove = [1,2,3,6]
new_list= [ value for index, value in enumerate(list) if index not
in index_remove]
print(new_list)
3) a
A=[1,1,3,3,5,6,7,8,6,4,5,6,5]
B=[]
for i in A:
if i not in B:
B.append(i)
print(B)
3) b
A=[1,1,3,3,5,6,7,8,6,4,5,6,5]
B=[]
B=(list(set(A)))
print(B)
4) a
A=[1,1,3,3,5,6,7,8,6,4,5,6,5]
B=[]
for x in A:
if(x not in B):
B.append(x)
for x in B:
Count=A.count(x)
print(x,Count)
4) b
A=[1,1,3,3,5,6,7,8,6,4,5,6,5]
B=(list(set(A)))
for x in B:
Count=A.count(x)
print(x,Count)
5) a
n = int(input("Nhập số lượng phần tử"))
A=[]
for i in range(n):
x=int(input("Nhập phần tử"))
A.append(x);
print(A)
5) b
A=[]
while True:
x= int(input("Nhập phần tử "))
if x==-1:
break
A.append(x)
print(A)
6) a
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c=[]
for i in a:
if i in b:
c.append(i)
print(c)
6) b
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c=[x for x in a if x in b]
print(c)

DICTIONARY
B
1)
set = set(range(201))
print(set)
2)
def checkPrime(x):
x=int(x)
if(x==1):
return False;
if(x==2):
return True;
for i in range(2,x//2):
if(x%i==0) :
return False
return True
A=set(x for x in range(10,2000) if checkPrime(x) == True)
print(A)
3)
import random

a=set(random.randint(10,2000) for x in range(10))


print(a)
b=set(random.randint(10,2000) for x in range(10))
print(b)
c=b.intersection(a)
d=b.union(a)
e=b.difference(a)
f=b.symmetric_difference(a)

print(c)
print(d)
print(e)
print(f)
4)
a=dict()
for i in range(5):
key=int(input('key:'))
value = int(input('value:'))
a[key] = value
b=set()
for key in a:
b.add(a[key])
print(a)
print(b)
5)
a=dict()
for i in range(5):
key=int(input('key:'))
value = int(input('value:'))
a[key] = value
print(max(a.values()))
6)
import operator

n=10
a=dict()
for i in range(n):
key = int(input("key:"))
value = int(input("value:"))
a[key] = value
b = max(a.items(),key=operator.itemgetter(1))[0]
print(b)
del a[b]
b = max(a.items(),key=operator.itemgetter(1))[0]
print(b)

You might also like