Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Recap
Tuples as return types in functions
Tuples as records
List of tuples
12. Removing tuples from lists
Summary

Instruction

Great! Here is another example where we combine list and tuple techniques:

cars_to_sell = [
  ('Volvo', 18000, 137000),
  ('BMW', 23000, 80000),
  ('Opel', 12000, 75000),
  ('Ford', 14500, 100000)
]

def remove_cars_above_15k(car_list):
  for car in car_list[:]:
    if car[1] > 15000:
      car_list.remove(car)

remove_cars_above_15k(cars_to_sell)

In the above code, we remove cars priced above $15,000. Note that we iterated over a copy of the input list – we used car_list[:] in the for loop – to avoid incorrect results. This is a trick we learned in the previous part.

Exercise

Create a function named remove_sql_specialists(people_list) that, given a list of tuples in the format shown in the template code, removes people whose job titles contain the word "SQL" from the list.

Stuck? Here's a hint!

You can use the in operator to check if a given job title contains the word "SQL":

if 'SQL' in position:
  ...