Fastest method to generate big random string with lower Latin letters

后端 未结 8 1888
难免孤独
难免孤独 2020-12-06 05:38

I\'m trying to solve this problem from Timus Online Judge. To solve this problem you need generate a sequence of 1 000 000 lowercase Latin letters and write it to stdin in

8条回答
  •  萌比男神i
    2020-12-06 06:00

    Use random.choices?

    On Python 3.6:

    import random
    import string
    
    %timeit ''.join(random.choices(string.ascii_lowercase, k=10**6))
    1 loop, best of 3: 235 ms per loop
    

提交回复
热议问题