Manipulating tuples Let aTuple be a tuple of tuples, such that the inner tuples are all of type (int,string).

def get_data(aTuple):
  nums = ()    # empty tuple
  words = ()
  for t in aTuple:
    nums = nums + (t[0],) #singleton tuple
    if t[1] not in words:
      words = words + (t[1],)  #singleton tuple
  min_n = min(nums)
  max_n = max(nums)
  unique_words = len(words)
  return (min_n, max_n, unique_words)
The get_data function identifies the minimum and the maximum numbers in the constituent tuples, and also the number of unique words (strings) in the constituent tuples.

Lists

Indices and ordering

a_list = []
L = [2, 'a', 4, [1,2]]
len(L) evaluates to 4
L[0] evaluates to 2
L[2]+1 evaluates to 5
L[3] evaluates to [1,2], another list!
L[4] gives an error
i = 2
L[i-1] evaluates to 'a' because L[1]='a'

Lists are mutable

Iterating over a list

Operations on Lists - Add

Operations on Lists - Remove

Convert lists to strings and back

s = "I<3 cs"  #s is a string
list(s)   #returns ['I','<','3',' ','c','s']
s.split('<')  #returns ['I', '3 cs']
L = ['a','b','c']  # L is a list
''.join(L)    #returns "abc"
'_'.join(L)   #returns "a_b_c"

Other list operations

L = [9,6,0,3]
sorted(L)   # returns sorted list, does not mutate L
L.sort()    # mutates L to [0,3,6,9]
L.reverse() # mutates L to [9,6,3,0]