Advertisement
Spocoman

04. Search

Jan 21st, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. num = int(input())
  2. word = input()
  3. lst = []
  4. filtered = []
  5.  
  6. for i in range(num):
  7.     text = input()
  8.     filtered.append(text) if word in text else lst.append(text)
  9.  
  10. print(f'{lst}\n{filtered}')
  11.  
  12.  
  13. Или:
  14.  
  15. num = int(input())
  16. word = input()
  17. lst = []
  18.  
  19. for i in range(num):
  20.     lst.append(input())
  21.  
  22. print(f'{lst}\n{[x for x in lst if word in x]}') # print(f'{lst}\n{list(filter(lambda x: word in x, lst))}')
  23.  
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement