Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- # Ransom note
- # The code will take the following input from STDIN
- # First line, length of the strings input
- # Second Line is the string representing the text of the words in the magazine to be used for creating a ransom note
- # Third line is the string representing the text of the words in the ransom note
- # Program will print Yes if the ransom note can be created from the given magazine, and No otherwise.
- def ransom_note(magazine, ransom):
- magazine_dict = {}
- for word in magazine:
- if word not in magazine_dict:
- magazine_dict[word] = magazine.count(word)
- ransom_dict = {}
- for word in ransom:
- if word not in ransom_dict:
- ransom_dict[word] = ransom.count(word)
- ransom_set = set(ransom_dict.keys())
- magazine_set = set(magazine_dict.keys())
- if not ransom_set.issubset(magazine_set):
- return False
- else:
- for word in ransom_set:
- if ransom_dict[word] > magazine_dict[word]:
- return False
- return True
- m, n = map(int, raw_input().strip().split(' '))
- magazine = raw_input().strip().split(' ')
- ransom = raw_input().strip().split(' ')
- answer = ransom_note(magazine, ransom)
- if(answer):
- print "Yes"
- else:
- print "No"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement