About 244,000 results
Open links in new tab
  1. python - Convert a list with strings all to lowercase or uppercase ...

    I have a Python list variable that contains strings. Is there a function that can convert all the strings in one pass to lowercase and vice versa, uppercase?

  2. 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: …

  3. python - How do I clone a list so that it doesn't change …

    While new_list = old_list[:], copy.copy(old_list)' and for Py3k old_list.copy() work for single-leveled lists, they revert to pointing at the list objects nested within the old_list and the new_list, and …

  4. Create list of single item repeated N times - Stack Overflow

    Apr 16, 2024 · 825 I want to create a series of lists, all of varying lengths. Each list will contain the same element e, repeated n times (where n = length of the list). How do I create the lists, …

  5. python - How do I make a flat list out of a list of lists? - Stack …

    If your list of lists comes from a nested list comprehension, the problem can be solved more simply/directly by fixing the comprehension; please see How can I get a flat result from a list …

  6. 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,...

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

  8. python - Making all possible combinations of a list - Stack Overflow

    I need to be able to make a list that contains all possible combinations of an inputted list. For example the list [1,2,3] should return [1 [1,2] [1,3] 2 [2,3] 3 [1,2,3]] The list doesn't have to be …

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

    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 …

  10. python - Make a dictionary (dict) from separate lists of keys and ...

    Imagine that you have: keys = ('name', 'age', 'food') values = ('Monty', 42, 'spam') What is the simplest way to produce the following dictionary ? dict = {'name' : 'Monty', 'age' : 42, 'food' : …