I'm trying to set a tuple of integers as the key for my dictionary. Here is the relevant code:
class Solution:
def longestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
paldict = {}
stringlen = len(s)
for i in range(len(s)):
if self.isPalindrome(s[i]) == True:
paldict[(i, i)] = True
else:
paldict[(i, i)] = False
for key, value in paldict:
print(key)
print(value)
The second for loop is just for testing because the compiler was telling me that when I tried to access the second element, that int types are not subscriptable which to me was strange. That was an error which should only occur if the type wasn't a tuple. Upon printing out, I saw that the keys were actually only a single integer instead of a tuple. Also, the value wasn't True or False, but the same integer again. Any ideas why?