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


Python OrderedDict.fromkeys方法代码示例

本文整理汇总了Python中collections.OrderedDict.fromkeys方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.fromkeys方法的具体用法?Python OrderedDict.fromkeys怎么用?Python OrderedDict.fromkeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collections.OrderedDict的用法示例。


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

示例1: build_vocab

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def build_vocab(self, *args, **kwargs):
        counter = Counter()
        sources = []
        for arg in args:
            if isinstance(arg, Dataset):
                sources += [getattr(arg, name) for name, field in arg.fields.items() if field is self]
            else:
                sources.append(arg)

        for data in sources:
            for x in data:
                x = self.preprocess(x)
                try:
                    counter.update(x)
                except TypeError:
                    counter.update(chain.from_iterable(x))

        specials = list(OrderedDict.fromkeys([
            tok for tok in [self.unk_token, self.pad_token, self.init_token,
                            self.eos_token]
            if tok is not None]))
        self.vocab = self.vocab_cls(counter, specials=specials, **kwargs) 
开发者ID:aimagelab,项目名称:speaksee,代码行数:24,代码来源:field.py

示例2: random_play

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def random_play(data):
    """Generate a random play with plausible values for debugging purposes."""

    features = data['features']
    situation = OrderedDict.fromkeys(features)

    situation['dwn'] = 4
    situation['ytg'] = random.randint(1, 10)
    situation['yfog'] = random.randint(1, (100 - situation['ytg']))
    situation['secs_left'] = random.randint(1, 3600)
    situation['score_diff'] = random.randint(-20, 20)
    situation['timo'] = random.randint(0, 3)
    situation['timd'] = random.randint(0, 3)
    situation['spread'] = 0

    situation = calculate_features(situation, data)

    situation['dome'] = random.randint(0, 1)
    return situation 
开发者ID:TheUpshot,项目名称:4thdownbot-model,代码行数:21,代码来源:winprob.py

示例3: __init__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def __init__(self, case, recipe, decomposeParDict=None, solution_parameter=None,
                 remove_extra_foam_files=False):
        """Init solution."""
        self.__remove = remove_extra_foam_files
        assert hasattr(case, 'isCase'), \
            'ValueError:: {} is not a Butterfly.Case'.format(case)
        self.decomposeParDict = decomposeParDict

        self.__case = case
        self.case.decomposeParDict = self.decomposeParDict

        self.recipe = recipe
        self.update_solution_params(solution_parameter)
        # set internal properties for running the solution

        # place holder for residuals
        self.__residualValues = OrderedDict.fromkeys(self.residual_fields, 0)
        self.__isRunStarted = False
        self.__isRunFinished = False
        self.__process = None
        self.__log_files = None
        self.__errFiles = None 
开发者ID:ladybug-tools,项目名称:butterfly,代码行数:24,代码来源:solution.py

示例4: output

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def output():
    try:
        if not args.outputFile:
            args.outputFile = 'smeegescrape_out.txt'
        outputFile = open(args.outputFile, 'w')
        wordListFinal = OrderedDict.fromkeys(wordList).keys()
        
        for word in wordListFinal:
            outputFile.write(word)
            outputFile.write('\n')
        outputFile.close()
        
        print '\n{0} unique words have been scraped.'.format(len(wordListFinal))
        print 'Output file successfully written: {0}'.format(outputFile.name)
    except Exception as e:
        print 'Error creating output file: {0}'.format(outputFile.name)
        print e 
开发者ID:SmeegeSec,项目名称:SmeegeScrape,代码行数:19,代码来源:SmeegeScrape.py

示例5: get_filter_and_output

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def get_filter_and_output(self, lcf_thres, mismatches, target_genomes,
                              input, coverage,
                              mismatches_tolerant=-1,
                              lcf_thres_tolerant=-1,
                              cover_extension=0,
                              identify=False,
                              blacklisted_genomes=[],
                              cover_groupings_separately=False):
        input_probes = [probe.Probe.from_str(s) for s in input]
        # Remove duplicates
        input_probes = list(OrderedDict.fromkeys(input_probes))
        f = scf.SetCoverFilter(
            mismatches=mismatches,
            lcf_thres=lcf_thres,
            coverage=coverage,
            cover_extension=cover_extension,
            mismatches_tolerant=mismatches_tolerant,
            lcf_thres_tolerant=lcf_thres_tolerant,
            identify=identify,
            blacklisted_genomes=blacklisted_genomes,
            cover_groupings_separately=cover_groupings_separately,
            kmer_probe_map_k=3)
        output_probes = f.filter(input_probes, target_genomes)
        return (f, output_probes) 
开发者ID:broadinstitute,项目名称:catch,代码行数:26,代码来源:test_set_cover_filter.py

示例6: update

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def update(self, data):
        """Maps new values to integer identifiers.

        Parameters
        ----------
        data: iterable
              sequence of string values

        Raises
        ------
        TypeError
              If the value in data is not a string, unicode, bytes type
        """
        data = np.atleast_1d(np.array(data, dtype=object))

        for val in OrderedDict.fromkeys(data):
            if not isinstance(val, (str, bytes)):
                raise TypeError("{val!r} is not a string".format(val=val))
            if val not in self._mapping:
                self._mapping[val] = next(self._counter)


# Connects the convertor to matplotlib 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:25,代码来源:category.py

示例7: test_move_to_end

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def test_move_to_end(self):
        OrderedDict = self.OrderedDict
        od = OrderedDict.fromkeys('abcde')
        self.assertEqual(list(od), list('abcde'))
        od.move_to_end('c')
        self.assertEqual(list(od), list('abdec'))
        od.move_to_end('c', 0)
        self.assertEqual(list(od), list('cabde'))
        od.move_to_end('c', 0)
        self.assertEqual(list(od), list('cabde'))
        od.move_to_end('e')
        self.assertEqual(list(od), list('cabde'))
        od.move_to_end('b', last=False)
        self.assertEqual(list(od), list('bcade'))
        with self.assertRaises(KeyError):
            od.move_to_end('x')
        with self.assertRaises(KeyError):
            od.move_to_end('x', 0) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_collections.py

示例8: test_key_change_during_iteration

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def test_key_change_during_iteration(self):
        OrderedDict = self.OrderedDict

        od = OrderedDict.fromkeys('abcde')
        self.assertEqual(list(od), list('abcde'))
        with self.assertRaises(RuntimeError):
            for i, k in enumerate(od):
                od.move_to_end(k)
                self.assertLess(i, 5)
        with self.assertRaises(RuntimeError):
            for k in od:
                od['f'] = None
        with self.assertRaises(RuntimeError):
            for k in od:
                del od['c']
        self.assertEqual(list(od), list('bdeaf')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_collections.py

示例9: gen_table

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def gen_table(johnnydist, extra_cols=()):
    extra_cols = OrderedDict.fromkeys(extra_cols)  # de-dupe and preserve ordering
    extra_cols.pop("name", None)  # this is always included anyway, no need to ask for it
    johnnydist.log.debug("generating table")
    for pre, _fill, node in anytree.RenderTree(johnnydist):
        row = OrderedDict()
        name = str(node.req)
        if "specifier" in extra_cols:
            name = wimpy.strip_suffix(name, str(node.specifier))
        row["name"] = pre + name
        for col in extra_cols:
            val = getattr(node, col, "")
            if isinstance(val, list):
                val = ", ".join(val)
            row[col] = val
        yield row 
开发者ID:wimglenn,项目名称:johnnydep,代码行数:18,代码来源:lib.py

示例10: array_remove_duplicates

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def array_remove_duplicates(s):
    """removes any duplicated elements in a string array."""
    return list(OrderedDict.fromkeys(s)) 
开发者ID:casbin,项目名称:pycasbin,代码行数:5,代码来源:util.py

示例11: _notify_subscribers

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def _notify_subscribers(self, event):
        with self._attr.default.subscribers_lock:
            defaults = OrderedDict.fromkeys(
                (
                    s._default
                    for s in self._attr.default.subscribers
                    if s._default is not None
                )
            )
            for subscriber in self._attr.default.subscribers:
                checked = subscriber.notify(event)
                if checked:
                    if subscriber._default is not None:
                        defaults.pop(subscriber._default, None)
                    future = self._attr.default.subscribers_thread_loop.run_async(
                        subscriber.process
                    )
                    self._attr.default.running_subscribers[id(subscriber)] = future
                    future.add_done_callback(
                        functools.partial(
                            lambda subscriber, _: self._attr.default.running_subscribers.pop(
                                id(subscriber)
                            ),
                            subscriber,
                        )
                    )

            for default in defaults:
                default.notify(event)
                self._attr.default.subscribers_thread_loop.run_async(default.process) 
开发者ID:Parrot-Developers,项目名称:olympe,代码行数:32,代码来源:expectations.py

示例12: build_vocab

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def build_vocab(self, *args, **kwargs):
        """Construct the Vocab object for this field from one or more datasets.

        Arguments:
            Positional arguments: Dataset objects or other iterable data
                sources from which to construct the Vocab object that
                represents the set of possible values for this field. If
                a Dataset object is provided, all columns corresponding
                to this field are used; individual columns can also be
                provided directly.
            Remaining keyword arguments: Passed to the constructor of Vocab.
        """
        counter = Counter()
        sources = []
        for arg in args:
            if hasattr(arg, 'fields'):
                sources += [getattr(arg, name) for name, field in
                            arg.fields.items() if field is self]
            else:
                sources.append(arg)
        for data in sources:
            for x in data:
                if not self.sequential:
                    x = [x]
                counter.update(x)
        specials = [self.unk_token, self.pad_token, self.init_token, self.eos_token]
        specials = list(OrderedDict.fromkeys(tok for tok in specials if tok is not None))
        self.vocab = self.vocab_cls(counter, specials=specials, **kwargs) 
开发者ID:salesforce,项目名称:decaNLP,代码行数:30,代码来源:field.py

示例13: vocab_from_counter

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def vocab_from_counter(self, counter, **kwargs):
        specials = list(OrderedDict.fromkeys(
            tok for tok in [self.unk_token, self.pad_token, self.init_token,
                            self.eos_token]
            if tok is not None))
        self.vocab = self.vocab_cls(counter, specials=specials, **kwargs) 
开发者ID:salesforce,项目名称:decaNLP,代码行数:8,代码来源:field.py

示例14: _build_field_vocab

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def _build_field_vocab(field, counter, **kwargs):
    specials = list(OrderedDict.fromkeys(
        tok for tok in [field.unk_token, field.pad_token, field.init_token,
                        field.eos_token]
        if tok is not None))
    field.vocab = field.vocab_cls(counter, specials=specials, **kwargs) 
开发者ID:xiadingZ,项目名称:video-caption-openNMT.pytorch,代码行数:8,代码来源:IO.py

示例15: comment_handler_lines_deduplicate

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import fromkeys [as 别名]
def comment_handler_lines_deduplicate(self):
        self.comment_handler.lines = list(OrderedDict.fromkeys(self.comment_handler.lines)) 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:4,代码来源:ReviewBot.py


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