SimeonTs

SUPyF2 Lists Basics Lab - 04. Search

Sep 27th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. """
  2. Lists Basics - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1724#3
  4.  
  5. SUPyF2 Lists Basics Lab - 04. Search
  6.  
  7. Problem:
  8. You will receive a number n and a word. On the next n lines you will be given some strings.
  9. You have to add them in a list and print them.
  10. After that you have to filter out only the strings that include the given word and print that list also.
  11.  
  12. Examples:
  13. Input:
  14. 3
  15. SoftUni
  16. I study at SoftUni
  17. I walk to work
  18. I learn Python at SoftUni
  19. Output:
  20. ['I study at SoftUni', 'I walk to work', 'I learn Python at SoftUni']
  21. ['I study at SoftUni', 'I learn Python at SoftUni']
  22.  
  23. Input:
  24. 4
  25. tomatoes
  26. I love tomatoes
  27. I can eat tomatoes forever
  28. I don't like apples
  29. Yesterday I ate two tomatoes
  30.  
  31. Output:
  32. ['I love tomatoes', 'I can eat tomatoes forever', "I don't like apples", 'Yesterday I ate two tomatoes']
  33. ['I love tomatoes', 'I can eat tomatoes forever', 'Yesterday I ate two tomatoes']
  34. """
  35. n = int(input())
  36. word = input()
  37. my_list = []
  38. filtered_list = []
  39.  
  40. for how_many_times in range(n):
  41.     line = input()
  42.     my_list += [line]
  43.     if word in line:
  44.         filtered_list += [line]
  45.  
  46. print(my_list)
  47. print(filtered_list)
Add Comment
Please, Sign In to add comment