0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

numpy を使わないで配列の中身を右にローテーションする方法

Posted at

モジュールを使えない環境でリストの中身をn回ローテーションする機能実装するために、めちゃ頭悩ませたので備忘録として残す。

def rotateByTimes(list,n):
    for a in range(n):
        first = list[-1]
        remains = list[:-1]
        list[0] = first
        for b in range(len(list)-1):
            list[b+1] = remains[b]
    return list

list = [1,2,3,4,5]
print(rotateByTimes(list,n))
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?