title: Extracting the last items from nested lists in python
body: <p>I have some nested lists. I want to extract the last occurring element within each sublist (eg 'bye' for the first sublist). I then want to add all these last occurring elements ('bye', 'bye', 'hello' and 'ciao') to a new list so that I can count them easily, and find out which is the most frequently occurring one ('bye).</p>
  <p>The problem is that my code leaves me with an empty list. I've looked at <a href="https://stackoverflow.com/questions/62822696/extracting-first-and-last-element-from-sublists-in-nested-list">Extracting first and last element from sublists in nested list</a> and <a href="https://stackoverflow.com/questions/63199461/how-to-extract-the-last-item-from-a-list-in-a-list-of-lists-python">How to extract the last item from a list in a list of lists? (Python)</a> and they're not exactly what I'm looking for.</p>
  <p>Thanks for any help!</p>
  <pre><code>my_list = [['hello', 'bye', 'bye'], ['hello', 'bye', 'bye'], ['hello', 'hello', 'hello'], ['hello', 'bye', 'ciao']]
  
  # Make a new list of all of the last elements in the sublists
  new_list = []
  for sublist in my_list:
      for element in sublist:
          if sublist.index(element) == -1:
              new_list.append(element)
  
  # MY OUTPUT
  print(new_list)
  []
          
  # EXPECTED OUTPUT 
  ['bye', 'bye', 'hello', 'ciao']
  
  
  # I would then use new_list to find out what the most common last element is:
  most_common = max(set(new_list), key = new_list.count) 
  
  # Expected final output
  print(most_common)
  # 'bye'
  </code></pre>