About 300,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. 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: …

  3. Get unique values from a list in python - Stack Overflow

    Oct 15, 2012 · set - unordered collection of unique elements. List of elements can be passed to set's constructor. So, pass list with duplicate elements, we get set with unique elements and …

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

    Aug 19, 2021 · In python an easy way is: your_list = [] for i in range(10): your_list.append(i) You can also get your for in a single line like so: your_list = [] for i in range(10): your_list.append(i) …

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

    Aug 16, 2013 · That is a list in Python 2.x and behaves mostly like a list in Python 3.x. If you are running Python 3 and ...

  6. How do I return dictionary keys as a list in Python?

    Python >= 3.5 alternative: unpack into a list literal [*newdict]. New unpacking generalizations (PEP 448) were introduced with Python 3.5 allowing you to now easily do:

  7. join list of lists in python - Stack Overflow

    Apr 4, 2009 · Is the a short syntax for joining a list of lists into a single list( or iterator) in python? For example I have a list as follows and I want to iterate over a,b and c. x = [["a","b"], ["c"]] The …

  8. How to make lists contain only distinct element in Python?

    Dec 18, 2017 · The characteristics of sets in Python are that the data items in a set are unordered and duplicates are not allowed. If you try to add a data item to a set that already contains the …

  9. python - How to empty a list? - Stack Overflow

    Feb 10, 2020 · index=len(list)-1 while index>=0: del list[index] index-=1 You have to start index at the length of the list and go backwards versus index at 0, forwards because that would end …

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

    Sep 6, 2012 · That will create a list (a type of mutable array in python) called my_list with the output of the np.getfromtext() method in the first 2 indexes. The first can be referenced with …

Refresh