About 50 results
Open links in new tab
  1. python - Why does += behave unexpectedly on lists? - Stack Overflow

    Otherwise it will instead try to use the plain __add__ and return a new object. That is why for mutable types like lists += changes the object's value, whereas for immutable types like tuples, strings and …

  2. Difference between del, remove, and pop on lists in Python

    Difference between del, remove, and pop on lists in Python Asked 13 years, 9 months ago Modified 2 years, 2 months ago Viewed 2.1m times

  3. python - List vs tuple, when to use each? - Stack Overflow

    In Python, when should you use lists and when tuples? Sometimes you don't have a choice, for example if you have "hello %s you are %s years old" % x then x must be a tuple. But if I am the one who

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

    The colon, :, is what tells Python you're giving it a slice and not a regular index. That's why the idiomatic way of making a shallow copy of lists in Python 2 is

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

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

    In Python 3, zip now returns a lazy iterator, and this is now the most performant approach. dict(zip(keys, values)) does require the one-time global lookup each for dict and zip, but it doesn't form any …

  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. What are the advantages of NumPy over regular Python lists?

    NumPy's arrays are more compact than Python lists -- a list of lists as you describe, in Python, would take at least 20 MB or so, while a NumPy 3D array with single-precision floats in the cells would fit in …

  9. python - Element-wise addition of 2 lists? - Stack Overflow

    Sep 10, 2013 · 6 This will work for 2 or more lists; iterating through the list of lists, but using numpy addition to deal with elements of each list

  10. Python list vs. array – when to use? - Stack Overflow

    Aug 17, 2022 · Lists are faster, because operations on array "raw" data need to continuously create and destroy python objects when reading from or writing to the array.