+ 1

Using list comprehension on list_q2_1 and list_q2_2 create a new list containing value pairs, where one of them is divisible by

Using list comprehension on list_q2_1 and list_q2_2 create a new list containing value pairs, where one of them is divisible by another, but does not include two equal elements. For example, (13, 91) should be included, but (91,91) should not). list_q2_1 = [97, 29, 43, 96, 91, 22, 51, 83, 31, 13, 62, 19, 23, 26, 50, 70, 84, 67, 36, 35] print(list_q2_1) print(len(list_q2_1)) list_q2_2 = [31, 63, 98, 91, 46, 71, 37, 70, 75, 33, 74, 77, 40, 10, 11, 57, 84, 64, 18, 28] print(list_q2_2) pair=[] for i in range(len(list_q2_2)): for j in range(len(list_q2_2)): if list_q2_2[i]%list_q2_1[j]==0 and list_q2_1[i]!=list_q2_2[j]: pair.append((list_q2_1[i],list_q2_2[j])) print(pair) why is my implementation incorrect would you help to fix it?

3rd Oct 2021, 9:35 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
1 Resposta
3rd Oct 2021, 10:05 AM
Slick
Slick - avatar