Last active
December 15, 2015 18:29
-
-
Save diezguerra/5303711 to your computer and use it in GitHub Desktop.
Python Slice Upsert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a_range = range(12) | |
a_range[-2:] = range(10,20) | |
assert a_range == range(20) | |
a_range[10:11] = range(10)[::-1] | |
a_range[20:] = [] | |
assert a_range == range(10) + range(10)[::-1] | |
keywords = "apple, pear, banana, lemon and orange" | |
keywords = keywords.split(', ') | |
keywords[-1:] = keywords[-1].split(' and ') | |
assert keywords == ["apple", "pear", "banana", "lemon", "orange"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For comparison, this is what [].extend looks like: