Slicing and Dicing
(, en)
Als Referenz für mich.
(all) a[:] -> ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
(first/head) a[:1] -> ['a']
(tail) a[1:] -> ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
(last) a[-1:] -> ['k']
(skip last) a[:-1] -> ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
(last 3) a[-3:] -> ['i', 'j', 'k']
(first 6) a[:6] -> ['a', 'b', 'c', 'd', 'e', 'f']
(skip last 3) a[:-3] -> ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
(skip first 7) a[7:] -> ['h', 'i', 'j', 'k']
(4th till 8th) a[3:8] -> ['d', 'e', 'f', 'g', 'h']
(4th till 2nd last) a[3:-1] -> ['d', 'e', 'f', 'g', 'h', 'i', 'j']
(4th last till 2nd last) a[-3:-1] -> ['i', 'j']
(reverse list) a[::-1] -> ['k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']
(every 2nd item) a[::2] -> ['a', 'c', 'e', 'g', 'i', 'k']
(every 2nd item, last to first) a[::-2] -> ['k', 'i', 'g', 'e', 'c', 'a']