dimanche 4 août 2019

I tried the Hash Tables: Ransom Note problems but obtained conflict results in some tests

I applied an if statement in the function, but it returned conflict results.

The function is to match words with magazines. It returns both 'Yes' and 'No' after an if statement. Can anyone take a look what I have done wrong? Thanks. The test inputs are:

magazine=['give', 'me', 'one', 'grand', 'today', 'night']

note=['give', 'one', 'grand', 'today']

"""python

import math
import os
import random
import re
import sys
from collections import Counter
# Complete the checkMagazine function below.
def checkMagazine(magazine, note):
    m=Counter(magazine)
    d=Counter(note)
    match=False
    newdict = {k: m[k] for k in d}
    if newdict.items()>=d.items():
        match=True
    if match:
        print("Yes")
    print("No")

"""

No errors, it just doesn't match the answers. The answer should be "Yes", but my function returns both "Yes" and "No".

Aucun commentaire:

Enregistrer un commentaire