Advertisement
SimeonTs

SUPyF2 Lists-Advanced-Exercise - 01. Which Are In?

Oct 10th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. """
  2. Lists Advanced - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1731#0
  4.  
  5. SUPyF2 Lists-Advanced-Exercise - 01. Which Are In?
  6.  
  7. Problem:
  8. Given two lists of strings print a new list of the strings that contains words from the first list
  9. which are substrings of any of the strings in the second list (only unique values)
  10.  
  11. Input
  12. There will be 2 lines of input: the two lists separated by ", "
  13.  
  14. Output
  15. Print the resulting list on the console
  16.  
  17. Example
  18. Input:
  19. arp, live, strong
  20. lively, alive, harp, sharp, armstrong
  21. Output:
  22. ['arp', 'live', 'strong']
  23.  
  24. Input:
  25. tarp mice bull
  26. lively alive harp sharp armstrong
  27.  
  28. Output:
  29. []
  30. """
  31. words_1 = input().split(", ")
  32. words_2 = input().split(", ")
  33. words_3 = []
  34. for word_1 in words_1:
  35.     for word_2 in words_2:
  36.         if word_1 in word_2:
  37.             if word_1 not in words_3:
  38.                 words_3.append(word_1)
  39. print(words_3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement