Last active
December 30, 2015 16:09
-
-
Save liuyix/7853143 to your computer and use it in GitHub Desktop.
Revisions
-
liuyix revised this gist
Dec 11, 2013 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -21,4 +21,8 @@ class Foo(object): True ``` ### 排序——lambda匿名函数 `result = sorted(memory_dict, key=lambda elem: elem[0]+elem[1], reverse=True)` link: http://docs.python.org/2/tutorial/controlflow.html#lambda-expressions -
liuyix revised this gist
Dec 8, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ class Foo(object): ```python >> mydict = {'foo': 'foo', 'bar': 'bar', 'hi':'hi'} >> set(['foo', 'bar']) <= set(mydict) True ``` -
liuyix revised this gist
Dec 8, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class Foo(object): ### dict判断是否具有某些key ```python >> mydict = {'foo': 'foo', 'bar': 'bar', 'hi':'hi'} >> set(['foo', 'bar']) <= set(mydit) True -
liuyix revised this gist
Dec 8, 2013 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,4 +13,12 @@ class Foo(object): `pack_info = dict((key, p.__dict__[key]) for key in Package.json_members)` **实现字典的部分拷贝** ### dict判断是否具有某些key ``` >> mydict = {'foo': 'foo', 'bar': 'bar', 'hi':'hi'} >> set(['foo', 'bar']) <= set(mydit) True ``` -
liuyix created this gist
Dec 8, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ ## Python Tips ### 建立class的最佳实践 credit:http://stackoverflow.com/a/62680 ```python class Foo(object): #... ``` 这样的建立方式,可以是Foo类自带`__dict__`,其中包含了所有类成员的字典,因此可以使用下面的语句: `pack_info = dict((key, p.__dict__[key]) for key in Package.json_members)` **实现字典的部分拷贝**