Skip to content
dreamcode
dreamcode
Projects
Cloud Diary
Guided projectPython
Reward: +220 XP
PROJECT BRIEF

Cloud Diary

Your cloud diary has grown long. Write filter_diary(entries, query) that returns every entry containing the query, keeping the diary's order.

The search ignores case, so "cloud" finds "Puffy Cloud today". It also ignores spaces around the query. A blank query matches nothing, because searching for nothing should not dump the whole diary.

Build it step by step
  1. Clean the query: trim it and lower-case it.
  2. If the cleaned query is empty, return an empty list straight away.
  3. Loop over the entries and keep the ones whose lower-case text contains the query.
Examples
filter_diary(['Saw a cyan cloud', 'Had a starry dream', 'Puffy Cloud today'], 'cloud')
['Saw a cyan cloud', 'Puffy Cloud today']
filter_diary(['Clear skies', 'Sunset was magenta'], 'rain')
[]
project.py
PYTHON
Saved as you type

Tests

0 of 4 passing
  • finds 'cloud' twice
    filter_diary(['Saw a cyan cloud', 'Had a starry dream', 'Puffy Cloud today'], 'cloud')
    expected ['Saw a cyan cloud', 'Puffy Cloud today']
  • no match
    filter_diary(['Clear skies', 'Sunset was magenta'], 'rain')
    expected []
  • query in capitals
    filter_diary(['rain again', 'sunny'], 'RAIN')
    expected ['rain again']
  • blank query matches nothing
    filter_diary(['anything'], ' ')
    expected []
On the line
+220 XP
Pass all 4 tests to claim it.