Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Recap
Tuples as return types in functions
5. Ignoring values with underscores
Tuples as records
List of tuples
Summary

Instruction

Good job! In the previous exercise, we unpacked the tuple returned from count_spaces_commas_stops() into three variables: spaces, commas, and stops. However, we didn't actually use the commas variable at all. Instead of creating an unnecessary variable, we can use an underscore (_). Take a look:

def count_spaces_commas_stops(text):
  spaces, commas, stops = 0, 0, 0 
  for letter in text:
    if letter == ' ':
      spaces += 1
    elif letter == ',':
      commas += 1
    elif letter == '.':
      stops += 1
  return (spaces, commas, stops)

input_text = 'In this example text, there are some commas, spaces and full stops. However, the text is not long.'
spaces, _, stops = count_spaces_commas_stops(input_text)
print('There are', spaces, 'spaces and', stops, 'full stops in the text.')

Notice that, this time, we didn't introduce the commas variable when we unpacked the tuple. Instead, we used an underscore (_). The spaces, _, stops notation means I know the function returns a tuple with three elements, but I only care about two of them.

Naturally, you can use more than one underscore if you want to ignore multiple tuple values.

Exercise

We never actually used the mean variable in the previous exercise! Modify the template code so that mean is not created at all.

Stuck? Here's a hint!

Unpack the tuple in the following way:

min, max, _ = get_min_max_mean(integers_example)