Last active
February 26, 2018 13:48
-
-
Save quiye/06836654fd133239898d055ca895c8de to your computer and use it in GitHub Desktop.
OrderedDictの継承
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
num=0 | |
from collections import OrderedDict | |
class TestExtends(OrderedDict): | |
def __init__(self): | |
OrderedDict.__init__(self) | |
def append(self,key,value): | |
global num | |
self[key]=value | |
self[num]=num+1 | |
num+=1 | |
print("値が追加されました:" + str(key)+str(value)) | |
if __name__ == "__main__": | |
test = TestExtends() | |
test.append("python",3) | |
test.append("-",'mmm') | |
test.append(1,'mmm') | |
test.append(22222222222,"izm") | |
test['hoge']=99 | |
test['hoge2']=99 | |
print "===============" | |
print test.keys() | |
print test.values() | |
print test.items() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment