About 388,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 …

  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 …

  3. python - How do I make a flat list out of a list of lists ... - Stack ...

    Dec 3, 2016 · A list of lists named xss can be flattened using a nested list comprehension: flat_list = [ x for xs in xss for x in xs ] The above is equivalent to: flat_list = [] for xs in xss: for x in xs: …

  4. python - Efficient way to either create a list, or append to it if one ...

    If you want list instead of set, you can do this: import collections d = collections.defaultdict(list) for a, b in mappings: d[b].append(a) – SilentGuy Commented Oct 29, 2020 at 22:05

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

    Jul 14, 2012 · The list(arg) is understood in other languages as calling a constructor of the list class. Actually, it is also the Python case. Actually, it is also the Python case. The debates …

  6. Making a list of evenly spaced numbers in a certain range in python

    Numpy's r_ convenience function can also create evenly spaced lists with syntax np.r_[start:stop:steps]. If steps is a real number (ending on j ), then the end point is included, …

  7. Create List of Single Item Repeated n Times in Python

    Apr 16, 2024 · The function itertools.repeat doesn't actually create the list, it just creates an object that can be used to create a list if you wish! Let's try that again, but converting to a list: >>> …

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

  9. How to convert a single number into a single item list in python

    Apr 13, 2015 · This will create a list called mylist with exactly one element i. This can be extended to create a list with as many values as you want: For example: mylist = [i1,i2,i3,i4] This creates …

  10. python - How do I fast make a list of 1~100? - Stack Overflow

    Apr 4, 2015 · Depends, if you are using Python 2.X it does but for Python 3.X it produces a range object which should be iterated upon to create a list if you need to. But in any case for all …

Refresh