dictionary={‘hello’:’v’,’3′:3, ‘True’:’value3′ ,’4.0′:’h’}
for key,value in dictionary.items():
try:
try:
try:
print(float(key))
except:
print(int(key))
except:
print(bool(key))
except:
print(key)
I have this code, I want to try and convert the keys(which arestrings) into either integers/booleans/floats and return the stringitself if they cannot. However, the output returns this:
True
3.0
True
4.0
I’m not sure why it doesnt return ‘hello’ , returns True twiceand int(3) as 3.0
Expert Answer
An answer will be send to you shortly. . . . .