pythonic way to do something N times without an index variable?

前端 未结 8 1179
一整个雨季
一整个雨季 2020-12-02 08:11

Every day I love python more and more.

Today, I was writing some code like:

for i in xrange(N):
    do_something()

I had to do som

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 08:57

    I just use for _ in range(n), it's straight to the point. It's going to generate the entire list for huge numbers in Python 2, but if you're using Python 3 it's not a problem.

提交回复
热议问题