天天看點

集合相關知識

set是一個無序且不重複的元素集合

class set(object):

    """

    set() -> new empty set object

    set(iterable) -> new set object

    Build an unordered collection of unique elements.

    def add(self, *args, **kwargs): # real signature unknown

        """ 添加 """

        """

        Add an element to a set.

        This has no effect if the element is already present.

        pass

    def clear(self, *args, **kwargs): # real signature unknown

        """ Remove all elements from this set. """

    def copy(self, *args, **kwargs): # real signature unknown

        """ Return a shallow copy of a set. """

    def difference(self, *args, **kwargs): # real signature unknown

        Return the difference of two or more sets as a new set.

        (i.e. all elements that are in this set but not the others.)

    def difference_update(self, *args, **kwargs): # real signature unknown

        """ 删除目前set中的所有包含在 new set 裡的元素 """

        """ Remove all elements of another set from this set. """

    def discard(self, *args, **kwargs): # real signature unknown

        """ 移除元素 """

        Remove an element from a set if it is a member.

        If the element is not a member, do nothing.

    def intersection(self, *args, **kwargs): # real signature unknown

        """ 取交集,新建立一個set """

        Return the intersection of two or more sets as a new set.

        (i.e. elements that are common to all of the sets.)

    def intersection_update(self, *args, **kwargs): # real signature unknown

        """ 取交集,修改原來set """

        """ Update a set with the intersection of itself and another. """

    def isdisjoint(self, *args, **kwargs): # real signature unknown

        """ 如果沒有交集,傳回true  """

        """ Return True if two sets have a null intersection. """

    def issubset(self, *args, **kwargs): # real signature unknown

        """ 是否是子集 """

        """ Report whether another set contains this set. """

    def issuperset(self, *args, **kwargs): # real signature unknown

        """ 是否是父集 """

        """ Report whether this set contains another set. """

    def pop(self, *args, **kwargs): # real signature unknown

        """ 移除 """

        Remove and return an arbitrary set element.

        Raises KeyError if the set is empty.

    def remove(self, *args, **kwargs): # real signature unknown

        Remove an element from a set; it must be a member.

        If the element is not a member, raise a KeyError.

    def symmetric_difference(self, *args, **kwargs): # real signature unknown

        """ 差集,建立新對象"""

        Return the symmetric difference of two sets as a new set.

        (i.e. all elements that are in exactly one of the sets.)

    def symmetric_difference_update(self, *args, **kwargs): # real signature unknown

        """ 差集,改變原來 """

        """ Update a set with the symmetric difference of itself and another. """

    def union(self, *args, **kwargs): # real signature unknown

        """ 并集 """

        Return the union of sets as a new set.

        (i.e. all elements that are in either set.)

    def update(self, *args, **kwargs): # real signature unknown

        """ 更新 """

        """ Update a set with the union of itself and others. """

    def __and__(self, y): # real signature unknown; restored from __doc__

        """ x.__and__(y) <==> x&y """

    def __cmp__(self, y): # real signature unknown; restored from __doc__

        """ x.__cmp__(y) <==> cmp(x,y) """

    def __contains__(self, y): # real signature unknown; restored from __doc__

        """ x.__contains__(y) <==> y in x. """

    def __eq__(self, y): # real signature unknown; restored from __doc__

        """ x.__eq__(y) <==> x==y """

    def __getattribute__(self, name): # real signature unknown; restored from __doc__

        """ x.__getattribute__('name') <==> x.name """

    def __ge__(self, y): # real signature unknown; restored from __doc__

        """ x.__ge__(y) <==> x>=y """

    def __gt__(self, y): # real signature unknown; restored from __doc__

        """ x.__gt__(y) <==> x>y """

    def __iand__(self, y): # real signature unknown; restored from __doc__

        """ x.__iand__(y) <==> x&=y """

    def __init__(self, seq=()): # known special case of set.__init__

        set() -> new empty set object

        set(iterable) -> new set object

        Build an unordered collection of unique elements.

        # (copied from class doc)

    def __ior__(self, y): # real signature unknown; restored from __doc__

        """ x.__ior__(y) <==> x|=y """

    def __isub__(self, y): # real signature unknown; restored from __doc__

        """ x.__isub__(y) <==> x-=y """

    def __iter__(self): # real signature unknown; restored from __doc__

        """ x.__iter__() <==> iter(x) """

    def __ixor__(self, y): # real signature unknown; restored from __doc__

        """ x.__ixor__(y) <==> x^=y """

    def __len__(self): # real signature unknown; restored from __doc__

        """ x.__len__() <==> len(x) """

    def __le__(self, y): # real signature unknown; restored from __doc__

        """ x.__le__(y) <==> x<=y """

    def __lt__(self, y): # real signature unknown; restored from __doc__

        """ x.__lt__(y) <==> x<y """

    @staticmethod # known case of __new__

    def __new__(S, *more): # real signature unknown; restored from __doc__

        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """

    def __ne__(self, y): # real signature unknown; restored from __doc__

        """ x.__ne__(y) <==> x!=y """

    def __or__(self, y): # real signature unknown; restored from __doc__

        """ x.__or__(y) <==> x|y """

    def __rand__(self, y): # real signature unknown; restored from __doc__

        """ x.__rand__(y) <==> y&x """

    def __reduce__(self, *args, **kwargs): # real signature unknown

        """ Return state information for pickling. """

    def __repr__(self): # real signature unknown; restored from __doc__

        """ x.__repr__() <==> repr(x) """

    def __ror__(self, y): # real signature unknown; restored from __doc__

        """ x.__ror__(y) <==> y|x """

    def __rsub__(self, y): # real signature unknown; restored from __doc__

        """ x.__rsub__(y) <==> y-x """

    def __rxor__(self, y): # real signature unknown; restored from __doc__

        """ x.__rxor__(y) <==> y^x """

    def __sizeof__(self): # real signature unknown; restored from __doc__

        """ S.__sizeof__() -> size of S in memory, in bytes """

    def __sub__(self, y): # real signature unknown; restored from __doc__

        """ x.__sub__(y) <==> x-y """

    def __xor__(self, y): # real signature unknown; restored from __doc__

        """ x.__xor__(y) <==> x^y """

    __hash__ = None

set

<code># 資料庫中原有</code>

<code>old_dict </code><code>=</code> <code>{</code>

<code>    </code><code>"#1"</code><code>:{ </code><code>'hostname'</code><code>:c1, </code><code>'cpu_count'</code><code>: </code><code>2</code><code>, </code><code>'mem_capicity'</code><code>: </code><code>80</code> <code>},</code>

<code>    </code><code>"#2"</code><code>:{ </code><code>'hostname'</code><code>:c1, </code><code>'cpu_count'</code><code>: </code><code>2</code><code>, </code><code>'mem_capicity'</code><code>: </code><code>80</code> <code>}</code>

<code>    </code><code>"#3"</code><code>:{ </code><code>'hostname'</code><code>:c1, </code><code>'cpu_count'</code><code>: </code><code>2</code><code>, </code><code>'mem_capicity'</code><code>: </code><code>80</code> <code>}</code>

<code>}</code>

<code># cmdb 新彙報的資料</code>

<code>new_dict </code><code>=</code> <code>{</code>

<code>    </code><code>"#1"</code><code>:{ </code><code>'hostname'</code><code>:c1, </code><code>'cpu_count'</code><code>: </code><code>2</code><code>, </code><code>'mem_capicity'</code><code>: </code><code>800</code> <code>},</code>

<code>    </code><code>"#4"</code><code>:{ </code><code>'hostname'</code><code>:c2, </code><code>'cpu_count'</code><code>: </code><code>2</code><code>, </code><code>'mem_capicity'</code><code>: </code><code>80</code> <code>}</code>

<code>需要删除:?</code>

<code>需要建立:?</code>

<code>需要更新:? 注意:無需考慮内部元素是否改變,隻要原來存在,新彙報也存在,就是需要更新</code>

      本文轉自027ryan  51CTO部落格,原文連結:http://blog.51cto.com/ucode/1716141,如需轉載請自行聯系原作者