|
| 1 | +''' |
| 2 | +Problem Statement |
| 3 | +Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below. |
| 4 | +The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value. |
| 5 | + |
| 6 | +The function should identify the degree of correctness as mentioned below: |
| 7 | +CORRECT, if it is an exact match |
| 8 | +ALMOST CORRECT, if no more than 2 letters are wrong |
| 9 | +WRONG, if more than 2 letters are wrong or if length (correct spelling versus spelling given by contestant) mismatches. |
| 10 | + |
| 11 | +and return a list containing the number of CORRECT answers, number of ALMOST CORRECT answers and number of WRONG answers. |
| 12 | +Assume that the words contain only uppercase letters and the maximum word length is 10. |
| 13 | + |
| 14 | +Sample Input |
| 15 | + |
| 16 | +{"THEIR": "THEIR", "BUSINESS": "BISINESS","WINDOWS":"WINDMILL","WERE":"WEAR","SAMPLE":"SAMPLE"} |
| 17 | + |
| 18 | +Expected Output |
| 19 | + |
| 20 | +[2, 2, 1] |
| 21 | +''' |
| 22 | + |
| 23 | +#lex_auth_01269444890062848087 |
| 24 | + |
| 25 | +def find_correct(word_dict): |
| 26 | + #start writing your code here |
| 27 | + res=[0,0,0] |
| 28 | + for x,y in word_dict.items(): |
| 29 | + if x == y: |
| 30 | + res[0] += 1 |
| 31 | + elif len(x) == len(y): |
| 32 | + count=0 |
| 33 | + for i in range(len(x)): |
| 34 | + if x[i] != y[i]: |
| 35 | + count += 1 |
| 36 | + if count <= 2: |
| 37 | + res[1] += 1 |
| 38 | + else: |
| 39 | + res[2] += 1 |
| 40 | + else: |
| 41 | + res[2] += 1 |
| 42 | + return res |
| 43 | + |
| 44 | + |
| 45 | +word_dict={"THEIR": "THEIR","BUSINESS":"BISINESS","WINDOWS":"WINDMILL","WERE":"WEAR","SAMPLE":"SAMPLE"} |
| 46 | +print(find_correct(word_dict)) |
0 commit comments