Anagram- Minimum number of char deletion required-'type' object is not subscriptable

Viewed 24

The below code doesnot work. Why the map function is returning type error? I have tried a many times. can someone give a proper reason for the below code?

n=26
string_array_1=[0]*n
string_array_2=[0]*n 
string_1='ababc'
string_2='abab'
for char in string_1:
    char_index=list(map[char])
    string_array_1[char_index]=string_array_1[char_index]+1
for char in string_2:
    char_index=string_2.index(char)
    string_array_2[char_index]=string_array_2[char_index]+1   
result=0
for i in range(26):
    abs_diff=abs(string_array_1[i]-string_array_2[i])
    result=result + abs_diff
print(result)
1 Answers

The problem comes from this part: list(map[char]). map(function, iterable, ...) is a Python built-in (function) that receives a function and applies it to an iterable. The real question is related to what do you expect to receive in char_index = list(map[char]).

Related