fork download
  1. def search_closet(items, colour):
  2. """ (list of str, str) -> list of str
  3.  
  4. items is a list containing descriptions of the contents of a closet where
  5. every description has the form 'colour item', where each colour is one word
  6. and each item is one or more word. For example:
  7.  
  8. ['grey summer jacket', 'orange spring jacket', 'red shoes', 'green hat']
  9.  
  10. colour is a colour that is being searched for in items.
  11.  
  12. Return a list containing only the items that match the colour.
  13.  
  14. >>> search_closet(['red summer jacket', 'orange spring jacket', 'red shoes', 'green hat'], 'red')
  15. ['red summer jacket', 'red shoes']
  16. >>> search_closet(['red shirt', 'green pants'], 'blue')
  17. []
  18. >>> search_closet([], 'mauve')
  19. []
  20. """
  21. resSet = []
  22. for item in items:
  23. if (colour in item and item[0] == colour[0]):
  24. resSet.append(item)
  25. return resSet
Success #stdin #stdout 0.02s 9100KB
stdin
Standard input is empty
stdout
Standard output is empty