Minimum number of letters removed, to make a string Peragram
The approach you are taking is to remove letters until at most one of them has an odd count. Once you realise that, the solution becomes obvious:

from collections import Counter

s = input() # don't call your own variable 'str'

c = Counter(s)

odds = [None for n in c.values() if n % 2]

if odds:
    print(len(odds) - 1)
else:
    print(0)


collections.Counter is a dict subclass to make counting the letters simpler. You don't actually need to create the substrings or check whether they are peragrams.



You should read and consider following the style guide, PEP-0008. For example:

if(IsPalindrome(str)):


should be:

if is_palindrome(s):