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

    In python, as far as I know, there are at least 3 to 4 ways to create and initialize lists of a given size: Simple loop with append: my_list = [] for i in range(50): my_list.append(0) Simple ...

  2. python - Dynamically create Literal alias from list of valid values ...

    I have a function which validates its argument to accept only values from a given list of valid options. Typing-wise, I reflect this behavior using a Literal type alias, like so: from typing import

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

    How do I create an empty list that can hold 10 elements? After that, I want to assign values in that list. For example: xs = list() for i in range(0, 9): xs[i] = i However, that gives IndexError:

  4. 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.

  5. python - How do I create a list with numbers between two values ...

    Dec 7, 2023 · How do I create a list of numbers between two values? For example, a list between 11 and 16: [11, 12, 13, 14, 15, 16]

  6. Python 3 turn range to a list - Stack Overflow

    Jul 14, 2012 · I'm trying to make a list with numbers 1-1000 in it. Obviously this would be annoying to write/read, so I'm attempting to make a list with a range in it. In Python 2 it seems that: some_list = …

  7. How to create a fix size list in python? - Stack Overflow

    May 16, 2012 · Actually if you know the length of the list it will be faster to create the "empty list" first of length n and then assign the values by index than it would to append each additional item.

  8. python - Automatically create file 'requirements.txt' - Stack Overflow

    Sometimes I download the Python source code from GitHub and don't know how to install all the dependencies. If there isn't any requirements.txt file I have to create it by hand. Given the Python so...

  9. Creating a list of integers in Python - Stack Overflow

    Aug 19, 2021 · Is it possible to create a list of integers with a single line of code, without using any third-party libraries? I tried with the syntax: lst = list(int(1234)) or the syntax: lst = list(int(1,2,3,...

  10. How to create a list from a text file in Python - Stack Overflow

    Aug 5, 2016 · I have a text file called "test", and I would like to create a list in Python and print it. I have the following code, but it does not print a list of words; it prints the whole document in one line.