Advertisement
viligen

task_1

Feb 19th, 2022
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. from collections import deque
  2.  
  3. flowers = ["rose", "tulip", "lotus", "daffodil"]
  4. vowels = deque(input().split())
  5. consonants = input().split()
  6. found_words = {}
  7. is_found = False
  8. while vowels and consonants:
  9.     vow = vowels.popleft()
  10.     cons = consonants.pop()
  11.     for word in flowers:
  12.         if vow in word:
  13.             if word not in found_words:
  14.                 found_words[word] = []
  15.             found_words[word].append(vow)
  16.             if set(word) == set(found_words[word]):
  17.                 print(f"Word found: {word}")
  18.                 is_found = True
  19.                 break
  20.  
  21.         if cons in word:
  22.             if word not in found_words:
  23.                 found_words[word] = []
  24.             found_words[word].append(cons)
  25.             if set(word) == set(found_words[word]):
  26.                 print(f"Word found: {word}")
  27.                 is_found = True
  28.                 break
  29.     if is_found:
  30.         break
  31. if not is_found:
  32.     print("Cannot find any word!")
  33. if vowels:
  34.     print("Vowels left:", *vowels)
  35. if consonants:
  36.     print("Consonants left:", *consonants)
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement