#!/usr/bin/python3 # -*- coding: utf-8 -*- # %% Slicing up containers """ Slicing can be applied to a variety of containers, lists, tuples, and strings included sliceable[start:stop:step] start: the beginning index of the slice, it will include the element at this index unless it is the same as stop, defaults to 0, i.e. the first index. If it's negative, it means to start n items from the end. stop: the ending index of the slice, it does not include the element at this index, defaults to length of the sequence being sliced, that is, up to and including the end. step: the amount by which the index increases, defaults to 1. If it's negative, you're slicing over the iterable in reverse. a[start:end] # items start through end-1 a[start:] # items start through the rest of the array a[:end] # items from the beginning through end-1 a[:] # a copy of the whole array # Below, indexs gap between before num, # allows for inserting a list into a list seq[num:num] seq[:] # [seq[0], seq[1], ..., seq[-1] ] seq[low:] # [seq[low], seq[low+1], ..., seq[-1] ] seq[:high] # [seq[0], seq[1], ..., seq[high-1]] seq[low:high] # [seq[low], seq[low+1], ..., seq[high-1]] seq[::stride] # [seq[0], seq[stride], ..., seq[-1] ] seq[low::stride] # [seq[low], seq[low+stride], ..., seq[-1] ] seq[:high:stride] # [seq[0], seq[stride], ..., seq[high-1]] seq[low:high:stride] # [seq[low], seq[low+stride], ..., seq[high-1]] seq[::-stride] # [seq[-1], seq[-1-stride], ..., seq[0] ] seq[high::-stride] # [seq[high], seq[high-stride], ..., seq[0] ] seq[:low:-stride] # [seq[-1], seq[-1-stride], ..., seq[low+1]] seq[high:low:-stride] # [seq[high], seq[high-stride], ..., seq[low+1]] x[::-1] # reverse a string """ # %% sequence functions operate on more than just lists, strings, etc. mylist = [3, 3, 4, 5] print(mylist) print(len(mylist)) print(min(mylist)) print(max(mylist)) print(sum(mylist)) print(mylist.index(3)) print(mylist.count(3)) print(len("hey")) print("hey".index("e")) print("heeeey".count("e"))