#hardwareid : location, current, low_temp, low_time, high_temp, high_time location_hw_map = {'285A9282300F1' : ['outside1', '0', '1', '2', '3', '4'], '123456789' : ['kitchen', '4', '3', '2', '1', '0'], '987654321' : ['attic', '', '', '', '', '']} # search string testString = "uyrfr-abcdefgh//foobar/123456789" # testing replacing a value to the list within the dictionary location_hw_map['123456789'][3] = '99' for i in location_hw_map: # Loops through every key in the dictionary if i in testString: # If the key is in the test string (if "123456789" is in "uyrfr..." print "location: "+location_hw_map[i][0] # Print the value of the key print "current temp: "+location_hw_map[i][1] print "low temp: "+location_hw_map[i][2] print "low temp time: "+location_hw_map[i][3] print "high temp: "+location_hw_map[i][4] print "high temp time: "+location_hw_map[i][5] break # We break out of the loop incase of multiple keys that are in the test string
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question