About 442,000 results
Open links in new tab
  1. Best and/or fastest way to create lists in python

    If you want to see the dependency with the length of the list n: Pure python. I tested for list length up to n=10000 and the behavior remains the same. So the integer multiplication method is the fastest with difference. Numpy. For lists with more than ~300 elements you should consider numpy. Benchmark code:

  2. List of zeros in python - Stack Overflow

    Dec 16, 2011 · There is a gotcha though, both itertools.repeat and [0] * n will create lists whose elements refer to same id. This is not a problem with immutable objects like integers or strings but if you try to create list of mutable objects like a list of lists ([[]] * n) then all the elements will refer to the same object.

  3. python - how to create a list of lists - Stack Overflow

    Sep 6, 2012 · In order to create a list of lists you will have firstly to store your data, array, or other type of variable into a list. Then, create a new empty list and append to it the lists that you just created. At the end you should end up with a list of lists: list_1=data_1.tolist() list_2=data_2.tolist() listoflists = [] listoflists.append(list_1 ...

  4. python - Creating and extending a list in one line - Stack Overflow

    Apr 13, 2012 · python create a list combined with an append. 5. Python: how to append to a list in the same line the list ...

  5. How to convert comma-delimited string to list in Python?

    Oct 21, 2011 · How do you explicitly convert a string to a list. Python-4. How to make list from text file in Python. 922.

  6. python - How can I generate a list of consecutive numbers

    Apr 10, 2015 · Note :-Certainly in python-3x you need to use Range function It works to generate numbers on demand, standard method to use Range function to make a list of consecutive numbers is

  7. Create a dictionary with list comprehension in Python

    This syntax was introduced in Python 3 and backported as far as Python 2.7, so you should be able to use it regardless of which version of Python you have installed. A canonical example is taking two lists and creating a dictionary where the item at each position in the first list becomes a key and the item at the corresponding position in the ...

  8. python - Create a List that contain each Line of a File - Stack …

    Nov 30, 2008 · You can't do someList[i] to put a new item at the end of a list. You must do someList.append(i). Also, never start a simple variable name with an uppercase letter. List confuses folks who know Python. Also, never use a built-in name as a variable. list is an existing data type, and using it as a variable confuses folks who know Python.

  9. python - How to create a list of a range with incremental step?

    Even though this has already been answered, I found that list comprehension made this super easy. I needed the same result as the OP, but in increments of 24, starting at -7 and going to 7. lc = [n*24 for n in range(-7, 8)]

  10. Create an empty list with certain size in Python - Stack Overflow

    To create a list of size 10(let's say), you can first create an empty array, like np.empty(10) and then convert it to list using arrayName.tolist(). Alternately, you can chain them as well. Alternately, you can chain them as well.

Refresh