當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。