Issue
so I will do my best to explain what I'm looking for, at the moment I have a 100 item list that I want to repetitively shuffle using a set pattern to first check if the pattern will eventually bring me back to where I began and 2 to print the result of each loop to a text file.
so using a 3 item list as my example [a,b,c] and the shuffle pattern [3 1 2] where the 3rd item becomes the first. the first item becomes the second and the second item becomes the 3rd on a loop would generate the following patterns
[a,b,c]
[3,1,2]
[c,a,b]
[b,c,a]
[a,b,c]
but I have a list at the moment of 100 items that I need to find every single arrangement for a few different patterns I would like to test out.
does anyone know of a way to do this in python please.
Solution
You can define function
and call this function
multi times like below:
>>> def func(lst, ptr):
... return [lst[idx-1] for idx in ptr]
>>> lst = ['a','b','c']
>>> ptr = [3,1,2]
>>> for _ in range(5):
... lst = func(lst, ptr)
... print(lst)
['c', 'a', 'b']
['b', 'c', 'a']
['a', 'b', 'c']
['c', 'a', 'b']
['b', 'c', 'a']
Answered By - user1740577
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.