About 1,740,000 results
Open links in new tab
  1. 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 …

  2. How to slice a list from an element n to the end in Python?

    How to slice a list from an element n to the end in Python? Asked 16 years, 8 months ago Modified 15 days ago Viewed 201k times

  3. What is :: (double colon) in Python when subscripting sequences?

    Aug 10, 2010 · 22 When slicing in Python the third parameter is the step. As others mentioned, see Extended Slices for a nice overview. With this knowledge, [::3] just means that you have …

  4. list - what does [::-1] mean in python - slicing? - Stack Overflow

    The method you used is called Slicing in Python. Slicing syntax in python is as follows, [ <first element to include> : <first element to exclude> : <step> ] where adding the step part is …

  5. How to slice a list in Python - Stack Overflow

    Suppose I have a list with X elements [4,76,2,8,6,4,3,7,2,1...] I'd like the first 5 elements. Unless it has less than 5 elements. [4,76,2,8,6] How to do that?

  6. Python slice first and last element in list - Stack Overflow

    Aug 31, 2012 · Python 3 only answer (that doesn't use slicing or throw away the rest of the list, but might be good enough anyway) is use unpacking generalizations to get first and last …

  7. Slicing a list using a variable, in Python - Stack Overflow

    May 13, 2012 · Given a list a = range(10) You can slice it using statements such as a[1] a[2:4] However, I want to do this based on a variable set elsewhere in the code. I can easily do this …

  8. Python: slicing a multi-dimensional array - Stack Overflow

    Feb 27, 2023 · Python's slicing also doesn't support 2D/multi-dimensional slicing for lists. The expected output for slicing a multi-dimensional list can be tricky. For example, If you want the …

  9. Why are Python's slice and range upper-bound exclusive?

    30 Elegant-ness VS Obvious-ness To be honest, I thought the way of slicing in Python is quite counter-intuitive, it's actually trading the so called elegant-ness with more brain-processing, …

  10. python - Slicing a dictionary - Stack Overflow

    I have a dictionary, and would like to pass a part of it to a function, that part being given by a list (or tuple) of keys. Like so: # the dictionary d = {1:2, 3:4, 5:6, 7:8} # the subset of keys ...