algorithm - Need a faster and efficient way to add elements to a list in python -
i trying create large list of numbers .
a = '1 1 1 2 2 0 0 1 1 1 1 9 9 0 0'
(it goes on ten million).
i've tried these methods:
%timeit l = list(map(int, a.split()))
4.07 µs per loop
%timeit l = a.split(' ')
462 ns per loop
%timeit l = [i in a.split()]
took1.19 µs per loop
i understand 2nd , 3rd variants character lists whereas first integer list, fine. number of elements gets on ten million, can take 6 seconds create list. long purposes. tell me more faster , efficient way this.
thanks
in plain python, not using third-party extension, a.split()
ought fastest way split input list. str.split()
function has 1 job , specialized use.
Comments
Post a Comment