import sys arrkey= [1, 2, 3, 4, 5, 6] arrval= [11, 12, 13, 14, 75, 45] #Make an array for keys and values # Adding values and keys to dictionary def add(key, value): for i in range(len(arrkey)): if key is arrkey[i]: sys.exit('Key is already taken') arrkey.append(key) arrval.append(value) print('key:', arrkey) print('value', arrval) #get the position of the key def get(key): for x in range(len(arrkey)): if key is arrkey[x]: return x return 'No Key found' #delete an entry def delete(key): w = int(get(key)) arrkey.pop(w) arrval.pop(w) print('key:', arrkey) print('value', arrval) #checking if the key is contained def contains(key): for x in range(len(arrkey)): if key is arrkey[x]: return 'True' return 'False' #getting length of the dictionary def length(): return (len(arrkey))
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