Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter
- from typing import List
- def find(words: List[str], needle: str) -> str:
- needle_frequency = Counter(needle)
- for word in words:
- if len(word) <= len(needle):
- word_frequency = Counter(word)
- matched_word = word
- for key in word_frequency.keys():
- if key not in needle_frequency or needle_frequency[key] < word_frequency[key]:
- matched_word = ""
- break
- if len(matched_word):
- return matched_word
- return "-"
- print(find(["baby", "referee", "cat", "dada", "dog", "bird", "ax"], "ctay"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement