python - I want to convert a string into list -


i giving string d='direct'
expected o/p= match found direct
getting match not found d
match not found i, match not found r etc. using code:

dict1={'d': 'direct', 't': '2',  'g': ['d','d']} dict2={'d': 'direct', 'u': ['2', '2'], 't': ['2', '2'],  'g': ['d', 'd']}  key in dict1:     index, element in enumerate(dict1[key]):         if element in dict2[key]:             print("match found for", element)         else:             print("match not found for", element) 

try code,

dict1={'d': 'direct', 't': '2',  'g': ['d','d']} dict2={'d': 'direct', 'u': ['2', '2'], 't': ['2', '2'],  'g': ['d', 'd']}  key1 in dict1:    key2 in dict2:         if key1 in key2:             print dict1[key1] 

you iterating on dict1, compares individual chars.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -