I want to perform the following:
>>> [0-2, 4] #case 1
[-2, 4] #I want the output to be [0, 1, 2, 4]
I know I can perform the same in this way:
>>> list(range(3)) + [4] #case 2
[0, 1, 2, 4]
But I am curious is there any way to achieve the same result using the case 1 method (or something similar)? Do I need to override the integer '-' operator or do I need to do anything with the list?
>>> [*range(0,3), 4]
[0, 1, 2, 4]
Should come closest. Python 3 only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With