Generating circular shifts / reduced Latin Squares in Python

前端 未结 7 1250
旧时难觅i
旧时难觅i 2020-12-31 19:38

Was just wondering what\'s the most efficient way of generating all the circular shifts of a list in Python. In either direction. For example, given a list [1, 2, 3, 4

7条回答
  •  庸人自扰
    2020-12-31 20:19

    Using itertools to avoid indexing:

    x = itertools.cycle(a)
    [[x.next() for i in a] for j in a]
    

提交回复
热议问题