Skip to content

Instantly share code, notes, and snippets.

@liuyix
Last active December 30, 2015 16:09
Show Gist options
  • Select an option

  • Save liuyix/7853143 to your computer and use it in GitHub Desktop.

Select an option

Save liuyix/7853143 to your computer and use it in GitHub Desktop.

Revisions

  1. liuyix revised this gist Dec 11, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions python-tips.md
    Original 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
  2. liuyix revised this gist Dec 8, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion python-tips.md
    Original 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(mydit)
    >> set(['foo', 'bar']) <= set(mydict)
    True
    ```

  3. liuyix revised this gist Dec 8, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion python-tips.md
    Original 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
  4. liuyix revised this gist Dec 8, 2013. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions python-tips.md
    Original 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
    ```


  5. liuyix created this gist Dec 8, 2013.
    16 changes: 16 additions & 0 deletions python-tips.md
    Original 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)`
    **实现字典的部分拷贝**