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:

  1. %timeit l = list(map(int, a.split())) 4.07 µs per loop
  2. %timeit l = a.split(' ') 462 ns per loop
  3. %timeit l = [i in a.split()] took 1.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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -