About 50 results
Open links in new tab
  1. python - What does list [x::y] do? - Stack Overflow

    Jan 27, 2012 · It slices x[startAt:endBefore:skip] if you use skip = 2, every other element the list beginning at startAt and ending at endBefore will be selected. [Remember: indices live BETWEEN …

  2. What is the difference between list [1] and list [1:] in Python?

    Oct 5, 2012 · By using a : colon in the list index, you are asking for a slice, which is always another list. In Python you can assign values to both an individual item in a list, and to a slice of the list.

  3. Python: list of lists - Stack Overflow

    First, I strongly recommend that you rename your variable list to something else. list is the name of the built-in list constructor, and you're hiding its normal function. I will rename list to a in the following. …

  4. How do I concatenate two lists in Python? - Stack Overflow

    406 How do I concatenate two lists in Python? As of 3.9, these are the most popular stdlib methods for concatenating two (or more) lists in Python. ... * A solution will qualify as a generalized solution if it …

  5. python - Find a value in a list - Stack Overflow

    In Python 3, filter doesn't return a list, but a generator-like object. Finding the first occurrence If you only want the first thing that matches a condition (but you don't know what it is yet), it's fine to use a for …

  6. python - Why does += behave unexpectedly on lists? - Stack Overflow

    177 The += operator in python seems to be operating unexpectedly on lists. Can anyone tell me what is going on here?

  7. Meaning of list[-1] in Python - Stack Overflow

    I have a piece of code here that is supposed to return the least common element in a list of elements, ordered by commonality: def getSingle(arr): from collections import Counter c = Counte...

  8. How can I compare two ordered lists in Python? - Stack Overflow

    Apr 5, 2016 · a = [0,2,1] b = [0,2,1] How can I compare these two lists to see if they are both equal/identical, with the constraint that they have to be in the same order? I have seen questions …

  9. python - Does "IndexError: list index out of range" when trying to ...

    Aug 11, 2022 · The way Python indexing works is that it starts at 0, so the first number of your list would be [0]. You would have to print [52], as the starting index is 0 and therefore line 53 is [52].

  10. slice - How slicing in Python works - Stack Overflow

    Python slicing is a computationally fast way to methodically access parts of your data. In my opinion, to be even an intermediate Python programmer, it's one aspect of the language that it is necessary to …