Here’s a note in Python list merging.
Environment
- Python 3.4.3
- Ubuntu 15.04
Bang or Non-Bang
In Python, we can merge 2 list in 2 way. extend
method and +
operator. But they effect in different way.
extend
method- Extends the list.
- Returns
None
.
+
operator- Creates a new list from 2 list.
- Returns a new merged list.
- The original lists are not changed.
Thus, extend
method is a bang method, you can fall into a bag spiral if you use it by mistake.