current position:Home>How do two lists compare in the same location

How do two lists compare in the same location

2022-02-03 00:10:00 CSDN Q & A

stay 1-33 Within the scope of , Randomly generate two containing 6 A list of elements . For example, a list of A:, list B:.
If the same position is compared, whether it is the same (a1 And b1,a2 And b2), Output the same number of two lists .

Refer to the answer 1:
sum0=0for i in range(len(a)):  #a,b There are two lists     if a[i]==b[i]:        sum0+=1print(sum0)

Refer to the answer 2:

Refer to the answer 3:
import randomlist_a = random.choices(range(1, 34), k=6)list_b = random.choices(range(1, 34), k=6)for i in range(4):    if list_a[i] == list_b[i]:        print(list_a[i])

Refer to the answer 4:

Refer to the answer 5:
import randomA = [random.randint(1,33) for i in range(6)]B = [random.randint(1,33) for i in range(6)]res = [1 if A[i] == B[i] else 0 for i in range(6)]print(" list A:", A)print(" list B:", B)print(f' The same number of elements in the same position of the two lists is :{sum(res)}')

Refer to the answer 6:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.

Random recommended