Python · Sets
Challenge 1
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercises
Exercise 1 — Daily Catch Count
You caught many Codémon today! Let's analyze your catches. - Count the total number of catches (including duplicates) and display it
Starter code
caught_today = [ 'Aquachu', 'Pyrochu', 'Aquachu', 'Florachu', 'Pyrochu', 'Aquachu', 'Zap', 'Pyrochu', 'Florachu', 'Aquachu', 'Rockachu', 'Zap' ]
Exercise 2 — Finding Unique Codémon
You noticed there are duplicates in your catches! Time to find which Codémon are unique. - Convert your catch list to a set to remove duplicates - Display the unique Codémon names - Count and display how many unique species you have
Starter code
caught_today = [ 'Aquachu', 'Pyrochu', 'Aquachu', 'Florachu', 'Pyrochu', 'Aquachu', 'Zap', 'Pyrochu', 'Florachu', 'Aquachu', 'Rockachu', 'Zap' ] print(f"Total catches: {len(caught_today)}")
Exercise 3 — Complete Catch Report
Time to analyze ALL your catches! Display how many times you caught each unique Codémon. - Loop through each unique Codémon - Count how many times each one appears in your catches - Display the name and count for each
Starter code
caught_today = [ 'Aquachu', 'Pyrochu', 'Aquachu', 'Florachu', 'Pyrochu', 'Aquachu', 'Zap', 'Pyrochu', 'Florachu', 'Aquachu', 'Rockachu', 'Zap' ] unique_codemon = set(caught_today)
Back to the course