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


Python MappingProxyType.items方法代码示例

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


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

示例1: object

# 需要导入模块: from types import MappingProxyType [as 别名]
# 或者: from types.MappingProxyType import items [as 别名]

#.........这里部分代码省略.........

    @classmethod
    def from_mass_fractions(cls, mass_fractions, formula=None):
        """
        Creates a composition from a mass fraction :class:`dict`.

        Args:
            mass_fractions (dict): mass fraction :class:`dict`.
                The keys are atomic numbers and the values weight fractions.
                Wildcard are accepted, e.g. ``{5: '?', 25: 0.4}`` where boron
                will get a mass fraction of 0.6.
            formula (str): optional chemical formula for the composition.
                If ``None``, a formula will be generated for the composition.
        """
        mass_fractions = process_wildcard(mass_fractions)
        atomic_fractions = convert_mass_to_atomic_fractions(mass_fractions)
        if not formula:
            formula = generate_name(atomic_fractions)
        return cls(cls._key, mass_fractions, atomic_fractions, formula)

    @classmethod
    def from_atomic_fractions(cls, atomic_fractions, formula=None):
        """
        Creates a composition from an atomic fraction :class:`dict`.

        Args:
            atomic_fractions (dict): atomic fraction :class:`dict`.
                The keys are atomic numbers and the values atomic fractions.
                Wildcard are accepted, e.g. ``{5: '?', 25: 0.4}`` where boron
                will get a atomic fraction of 0.6.
            formula (str): optional chemical formula for the composition.
                If ``None``, a formula will be generated for the composition.
        """
        atomic_fractions = process_wildcard(atomic_fractions)
        mass_fractions = convert_atomic_to_mass_fractions(atomic_fractions)
        if not formula:
            formula = generate_name(atomic_fractions)
        return cls(cls._key, mass_fractions, atomic_fractions, formula)

    def __len__(self):
        return len(self.mass_fractions)

    def __contains__(self, z):
        return z in self.mass_fractions

    def __iter__(self):
        return iter(self.mass_fractions.keys())

    def __repr__(self):
        return '<{}({})>'.format(self.__class__.__name__, self.inner_repr())

    def __eq__(self, other):
        if not isinstance(other, self.__class__):
            return False

        if len(self) != len(other):
            return False

        for z in self.mass_fractions:
            if z not in other.mass_fractions:
                return False

            fraction = self.mass_fractions[z]
            other_fraction = other.mass_fractions[z]

            if not math.isclose(fraction, other_fraction, abs_tol=self.PRECISION):
                return False

        return True

    def __ne__(self, other):
        return not self == other

    def __hash__(self):
        out = []
        for z in sorted(self.mass_fractions):
            out.append(z)
            out.append(int(self.mass_fractions[z] / self.PRECISION))

        return hash(tuple(out))

    def __getstate__(self):
        return {'mass_fractions': dict(self.mass_fractions),
                'atomic_fractions': dict(self.atomic_fractions),
                'formula': self.formula}

    def __setstate__(self, state):
        self.mass_fractions = MappingProxyType(state.get('mass_fractions', {}))
        self.atomic_fractions = MappingProxyType(state.get('atomic_fractions', {}))
        self._formula = state.get('formula', '')

    def is_normalized(self):
        return math.isclose(sum(self.mass_fractions.values()), 1.0, abs_tol=self.PRECISION)

    def inner_repr(self):
        return ', '.join('{}: {:.4f}'.format(pyxray.element_symbol(z), mass_fraction) for z, mass_fraction in self.mass_fractions.items())

    @property
    def formula(self):
        return self._formula
开发者ID:ppinard,项目名称:pyxray,代码行数:104,代码来源:composition.py

示例2: MappingProxyType

# 需要导入模块: from types import MappingProxyType [as 别名]
# 或者: from types.MappingProxyType import items [as 别名]
        ))),
    )))


stat_value = {
    '+MA': 30000,
    '+AG': 40000,
    '+ST': 50000,
    '+AV': 30000,
    }


## REDUNDANT BUT USEFUL ########################################

deck_of_card = MappingProxyType(
    {card: deck
        for deck, cards in cards_of_deck.items()
        for card in cards}
    )

card_price = MappingProxyType(
    {card: deck_price[deck]
        for card, deck in deck_of_card.items()}
    )

skillcat_by_skill = MappingProxyType(
    {skill: skillcat
        for skillcat, skills in skill_by_skillcat.items()
        for skill in skills}
    )
开发者ID:FUMBBLPlus,项目名称:fumbbl_base,代码行数:32,代码来源:crp.py

示例3: frozenset

# 需要导入模块: from types import MappingProxyType [as 别名]
# 或者: from types.MappingProxyType import items [as 别名]
        skill['Two Heads'],
        skill['Very Long Legs'],
        ))),
    (skillcat['RACIAL CHARACTERISTICS'], frozenset((
        skill['Always Hungry'],
        skill['Big Guy'],
        skill['Blood Lust'],
        skill['Bone Head'],
        skill['Easily Confused'],
        skill['Hypnotic Gaze'],
        skill['Nurgle\'s Rot'],
        skill['Really Stupid'],
        skill['Regeneration'],
        skill['Right Stuff'],
        skill['Stunty'],
        skill['Take Root'],
        skill['Throw Team-Mate'],
        skill['Thrud\'s Fans'],
        skill['Wild Animal'],
        ))),
    )))


## REDUNDANT BUT USEFUL ########################################

skillcat_by_skill = MappingProxyType(
    {skill: skillcat
        for skillcat, skills in skill_by_skillcat.items()
        for skill in skills}
    )
开发者ID:FUMBBLPlus,项目名称:fumbbl_base,代码行数:32,代码来源:lrb4.py


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