0
How to print k pairs of sequence elements in order using list?
Example: When k=3, list is [1,2,3,4] to print element in this order [2,3,4], [3,4,1], [4,1,2], [1,2,3] this all are possible pairs also. Please help to solve this problem!!
5 ответов
+ 2
Sabarinathan.M
a=[1,2,3,4]
print(list([a[1+i-4],a[2+i-4],a[3+i-4]] for i in range(4))).
The above solution might not work for other cases.
+ 1
You can use combination in itertools
from itertools import combinations
combinations(urlist, k)
0
Yes, combinations creating a pairs but i want to print above order, combinations will print this order (1, 2, 3),(1, 2, 4),(1, 3, 4),(2, 3, 4) it's different from my solution
0
What do you mean what is the order how do you define what comes first
0
Abhay your solution is static that's right but I need dynamic solution, how to do?