Discuss / Python / 有关list \tulpe\ dict \set综合练习 ,希望对大家有帮助

有关list \tulpe\ dict \set综合练习 ,希望对大家有帮助

Topic source

QQ

#1 Created at ... [Delete] [Delete and Lock User]

n=-1

M=list([0])

while n <= 10:

    n=n+1

    M.append(n+1)  # "M" is a variable that increases at any time;

    H=tuple(M)  # H=tuple(0,[M]);

    print(n)

print(H)

N=list(range(10))

M=tuple(range(10))

print(N)

print(M)

L=['SCORE']

for X in M:

    print(X)

    L.append(X)

    print(L)

    H=tuple(L)

print(H)

N=list(['hhh','kkk','ggg'])

M=tuple(N)

N.append('jjj')

print(N)

print(M)

for X in N :

    print(X)

S=-1

num=int((input('num:')))  # defined the "num" is int tepy; the number base on the "input()"

name=['A'] #must be defined the first element,which is locked the list

scroe=['B']

while S <= num:

    names=list([input('name1:')])

    scores=list([input('score1:')])

    name.append(names) # list is added the element base on the "input"

    H=list(name)   # "list()" is changed to the "tuple()" base on the "input" whthin in the range "S <=5";

    scroe.append(scores)

    L=list(scroe)

    print(H)

    print(L)

    S=S+1

    print(S)

print('all of is finished')

H.pop(0) # deleted the first element in the list(H)

L.pop(0) # deleted the first element in the list(L)

print(H)

print(L)

H=[item[0] for item in H]  # “List Comprehension ”,Basic grammatical structure is "[expression for item in iterable if condition]"

print(H)

L=[item[0] for item in L]

print(L)

name_scroe=dict(zip(H,L)) # "zip()" function making the list(H) and  list(L) to the dict(name_scroe)

print(name_scroe)

dict={1,2,3}

set={3,2,1}

if dict==set:  # judgement if these two assembles is alike;

    print('true')

else:

    print('faulse')


  • 1

Reply