当前位置: 首页>>代码示例>>Python>>正文


Python sortedcontainers.SortedSet类代码示例

本文整理汇总了Python中sortedcontainers.SortedSet的典型用法代码示例。如果您正苦于以下问题:Python SortedSet类的具体用法?Python SortedSet怎么用?Python SortedSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SortedSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_delitem_slice

def test_delitem_slice():
    vals = list(range(100))
    temp = SortedSet(vals)
    temp._reset(7)
    del vals[20:40:2]
    del temp[20:40:2]
    assert temp == set(vals)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py

示例2: test_union

def test_union():
    temp = SortedSet(range(0, 50), load=7)
    that = SortedSet(range(50, 100), load=9)
    result = temp.union(that)
    assert all(result[val] == val for val in range(100))
    assert all(temp[val] == val for val in range(50))
    assert all(that[val] == (val + 50) for val in range(50))
开发者ID:Muon,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py

示例3: test_copy

def test_copy():
    temp = SortedSet(range(100))
    temp._reset(7)
    that = temp.copy()
    that.add(1000)
    assert len(temp) == 100
    assert len(that) == 101
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py

示例4: get_links

def get_links(names, html):
    """
    Return a SortedSet of computer scientist names that are linked from this
    html page. The return set is restricted to those people in the provided
    set of names.  The returned list should contain no duplicates.

    Params:
      names....A SortedSet of computer scientist names, one per filename.
      html.....A string representing one html page.
    Returns:
      A SortedSet of names of linked computer scientists on this html page, restricted to
      elements of the set of provided names.

    >>> get_links({'Gerald_Jay_Sussman'},
    ... '''<a href="/wiki/Gerald_Jay_Sussman">xx</a> and <a href="/wiki/Not_Me">xx</a>''')
    SortedSet(['Gerald_Jay_Sussman'], key=None, load=1000)
    """

    pagenames = SortedSet()
    for link in BeautifulSoup(html, "html.parser", parse_only=SoupStrainer('a')):
        if link.has_attr('href'):
            name = link['href'].split('/')[-1]
            if name in names:
                pagenames.add(name)
    return pagenames
开发者ID:setr,项目名称:cs429,代码行数:25,代码来源:pagerank.py

示例5: get_links

def get_links(names, html):
    """
    Return a SortedSet of computer scientist names that are linked from this
    html page. The return set is restricted to those people in the provided
    set of names.  The returned list should contain no duplicates.

    Params:
      names....A SortedSet of computer scientist names, one per filename.
      html.....A string representing one html page.
    Returns:
      A SortedSet of names of linked computer scientists on this html page, restricted to
      elements of the set of provided names.

    >>> get_links({'Gerald_Jay_Sussman'},
    ... '''<a href="/wiki/Gerald_Jay_Sussman">xx</a> and <a href="/wiki/Not_Me">xx</a>''')
    SortedSet(['Gerald_Jay_Sussman'], key=None, load=1000)
    """
    soup = BeautifulSoup(html,"html.parser")
    list = [l['href'] for l in soup.find_all('a') if l.get('href')]
    res = SortedSet()
    for l in list:
        if l.startswith('/wiki/'):
            tokens = l.split('/')
            if tokens[2] in names:
                res.add(tokens[2])
    
    return res
开发者ID:deulgaonkaranup,项目名称:WebSearchEngine-API,代码行数:27,代码来源:pagerank.py

示例6: get_links

def get_links(names, html):
    """
    Return a SortedSet of computer scientist names that are linked from this
    html page. The return set is restricted to those people in the provided
    set of names.  The returned list should contain no duplicates.

    Params:
      names....A SortedSet of computer scientist names, one per filename.
      html.....A string representing one html page.
    Returns:
      A SortedSet of names of linked computer scientists on this html page, restricted to
      elements of the set of provided names.

    >>> get_links({'Gerald_Jay_Sussman'},
    ... '''<a href="/wiki/Gerald_Jay_Sussman">xx</a> and <a href="/wiki/Not_Me">xx</a>''')
    SortedSet(['Gerald_Jay_Sussman'], key=None, load=1000)
    """
    ###TODO
    found = SortedSet()
    bs = BeautifulSoup(html, "html.parser")
    for link in bs.find_all('a'):
        if link.get('href'):
            href = link.get('href')
            nl = re.split('|'.join(['/', '=', '&', ':', '/d+_']), href)
            cleared_nl = [n for n in nl if n != '']
            found = found.union([name for name in names if name in cleared_nl])
    return found
    pass
开发者ID:mickokenter,项目名称:flyingmatt,代码行数:28,代码来源:pagerank.py

示例7: __init__

 def __init__(self, root_path):
     self.code_graph = nx.MultiDiGraph()
     self.metrics = {}
     self.root_path = Path(root_path)
     self.root_arch_ids = []
     self.entity_kinds = SortedSet()
     self.ref_kinds = SortedSet()
开发者ID:ashapochka,项目名称:saapy,代码行数:7,代码来源:scitools_client.py

示例8: test_eq

def test_eq():
    alpha = SortedSet(range(100), load=7)
    beta = SortedSet(range(100), load=17)
    assert alpha == beta
    assert alpha == beta._set
    beta.add(101)
    assert not (alpha == beta)
开发者ID:gzgujs,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py

示例9: test_ne

def test_ne():
    alpha = SortedSet(range(100), load=7)
    beta = SortedSet(range(99), load=17)
    assert alpha != beta
    beta.add(100)
    assert alpha != beta
    assert alpha != beta._set
开发者ID:gzgujs,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedset.py

示例10: test_delitem_key

def test_delitem_key():
    temp = SortedSet(range(100), key=modulo)
    temp._reset(7)
    values = sorted(range(100), key=modulo)
    for val in range(10):
        del temp[val]
        del values[val]
    assert list(temp) == list(values)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py

示例11: test_symmetric_difference

def test_symmetric_difference():
    temp = SortedSet(range(0, 75), load=7)
    that = SortedSet(range(25, 100), load=9)
    result = temp.symmetric_difference(that)
    assert all(result[val] == val for val in range(25))
    assert all(result[val + 25] == (val + 75) for val in range(25))
    assert all(temp[val] == val for val in range(75))
    assert all(that[val] == (val + 25) for val in range(75))
开发者ID:Muon,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py

示例12: test_pickle

def test_pickle():
    import pickle
    alpha = SortedSet(range(10000), key=negate)
    alpha._reset(500)
    data = pickle.dumps(alpha)
    beta = pickle.loads(data)
    assert alpha == beta
    assert alpha._key == beta._key
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py

示例13: test_copy_copy

def test_copy_copy():
    import copy
    temp = SortedSet(range(100))
    temp._reset(7)
    that = copy.copy(temp)
    that.add(1000)
    assert len(temp) == 100
    assert len(that) == 101
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedset.py

示例14: DictGraph

class DictGraph(Graph):
    """Graph that supports nonconsecutive vertex ids."""

    def __init__(self, nodes: Set[int]=None, r: int=1) -> None:
        """Make a new graph."""
        if nodes is None:
            self.nodes = SortedSet()  # type: Set[int]
        else:
            self.nodes = nodes
        self.radius = r
        self.inarcs_by_weight = [defaultdict(SortedSet) for _ in range(self.radius)]

    def __len__(self):
        """len() support."""
        return len(self.nodes)

    def __iter__(self):
        """Iteration support."""
        return iter(self.nodes)

    def __contains__(self, v):
        """Support for `if v in graph`."""
        return v in self.nodes

    def add_node(self, u: int):
        """Add a new node."""
        self.nodes.add(u)

    def arcs(self, weight: int=None):
        """
        Return all the arcs in the graph.

        restrict to a given weight when provided
        """
        if weight:
            return [(x, y) for x in self.nodes
                    for y in self.inarcs_by_weight[weight-1][x]]
        else:
            return [(x, y, w+1) for w, arc_list in
                    enumerate(self.inarcs_by_weight)
                    for x in self.nodes
                    for y in arc_list[x]]

    def remove_isolates(self) -> List[int]:
        """
        Remove all isolated vertices and return a list of vertices removed.

        Precondition:  the graph is bidirectional
        """
        isolates = [v for v in self if self.in_degree(v, 1) == 0]
        for v in isolates:
            self.nodes.remove(v)
            for N in self.inarcs_by_weight:
                if v in N:
                    del N[v]
        return isolates
开发者ID:spacegraphcats,项目名称:spacegraphcats,代码行数:56,代码来源:graph.py

示例15: get_links

def get_links(names, html):
    """
    Return a SortedSet of computer scientist names that are linked from this
    html page. The return set is restricted to those people in the provided
    set of names.  The returned list should contain no duplicates.

    Params:
      names....A SortedSet of computer scientist names, one per filename.
      html.....A string representing one html page.
    Returns:
      A SortedSet of names of linked computer scientists on this html page, restricted to
      elements of the set of provided names.

    >>> get_links({'Gerald_Jay_Sussman'},
    ... '''<a href="/wiki/Gerald_Jay_Sussman">xx</a> and <a href="/wiki/Not_Me">xx</a>''')
    SortedSet(['Gerald_Jay_Sussman'], key=None, load=1000)
    """
    ###TODO
    #remove BeautifulSoap - later


    listofHrefs = []
    listofHrefTexts = []
    FinalSortedSet = SortedSet()
    splice_char = '/'
    #getting all the tags using the BeautifulSoup
    #soup = BeautifulSoup(html, "html.parser") 
    #fectching all the links in anchor tags
    #for link in soup.find_all('a'):
        #listofHrefs.append(link.get('href'))
    for i in range(0,len(listofHrefs)):
        value = listofHrefs[i][6:]
        listofHrefTexts.append(value)
    listofHrefTexts = re.findall(r'href="([^"]*)', html)
    #print(listofHrefTexts)
    for i in listofHrefTexts:
        #print(i)
        value = i[6:]
        listofHrefs.append(value)
    #print(listofHrefs)
    listofHrefs = list(set(listofHrefs))
    #print(len(listofHrefs))
    for href in listofHrefs:
        for name in names:
            #windows OS handling
            if(name == "Guy_L._Steele,_Jr"):
                names.remove(name)
                names.add("Guy_L._Steele,_Jr.")
            if(href == name):
                FinalSortedSet.add(name)
            
    
    return FinalSortedSet
    
    pass
开发者ID:BrindaRao,项目名称:IR_Assignments,代码行数:55,代码来源:pagerank.py


注:本文中的sortedcontainers.SortedSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。