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


Python ascii_lowercase.index方法代码示例

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


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

示例1: string_to_num

# 需要导入模块: from string import ascii_lowercase [as 别名]
# 或者: from string.ascii_lowercase import index [as 别名]
def string_to_num(string):
    from string import ascii_lowercase as alpha
    return sum([alpha.index(x) + 1 for x in string]) 
开发者ID:DestructHub,项目名称:ProjectEuler,代码行数:5,代码来源:solution_1.py

示例2: rotate

# 需要导入模块: from string import ascii_lowercase [as 别名]
# 或者: from string.ascii_lowercase import index [as 别名]
def rotate(message, key):
    coded_message = ""
    for char in message:
        if char in alpha_lower:
            char = alpha_lower[(alpha_lower.index(char) + key) % ALPHA_LEN]
        elif char in alpha_upper:
            char = alpha_upper[(alpha_upper.index(char) + key) % ALPHA_LEN]
        coded_message += char
    return coded_message 
开发者ID:exercism,项目名称:python,代码行数:11,代码来源:example.py

示例3: choose_role

# 需要导入模块: from string import ascii_lowercase [as 别名]
# 或者: from string.ascii_lowercase import index [as 别名]
def choose_role(self):
        """Flexible choice prompt for as many roles as the system has"""
        roles = [r for r in self.cork.list_roles()]
        formatted = ['{0} (level {1})'.format(*r) for r in roles]
        condensed = '\n'.join(['{0}.) {1}'.format(*t) for t in zip(alpha, formatted)])
        new_role = input('choose: \n{0}\n\n'.format(condensed))

        if new_role not in alpha[:len(roles)]:
            raise Exception('invalid role choice')

        return roles[alpha.index(new_role)][0] 
开发者ID:Rhizome-Conifer,项目名称:conifer,代码行数:13,代码来源:usermanager.py

示例4: get_string_from_search_contacts

# 需要导入模块: from string import ascii_lowercase [as 别名]
# 或者: from string.ascii_lowercase import index [as 别名]
def get_string_from_search_contacts(contacts):
    response_string = ""
    for index, contact in enumerate(contacts[:3]):
        contact = contact.object
        letter = ascii_lowercase[index]
        response_string += "{}: {} ({})\n".format(
            letter.upper(), contact.name, contact.get_complete_url(),
        )
    return response_string 
开发者ID:phildini,项目名称:logtacts,代码行数:11,代码来源:views.py

示例5: __init__

# 需要导入模块: from string import ascii_lowercase [as 别名]
# 或者: from string.ascii_lowercase import index [as 别名]
def __init__(self, bot):
        self.bot = bot
        self.ignore_next_removed_reaction = {}
        self.index = 0
        self.close_activate_polls.add_exception_type(KeyError)
        self.close_activate_polls.start()
        self.refresh_queue.start() 
开发者ID:matnad,项目名称:pollmaster,代码行数:9,代码来源:poll_controls.py

示例6: draw

# 需要导入模块: from string import ascii_lowercase [as 别名]
# 或者: from string.ascii_lowercase import index [as 别名]
def draw(self, ctx, short=None, opt=None):
        server = await ask_for_server(self.bot, ctx.message, short)
        if not server:
            return
        pre = await get_server_pre(self.bot, ctx.message.guild)
        if opt is None:
            error = f'No answer specified please use the following syntax: \n' \
                    f'`{pre}draw <poll_label> <answer_letter>`'
            await self.say_error(ctx, error)
            return
        if short is None:
            error = f'Please specify the label of a poll after the export command. \n' \
                    f'`{pre}export <poll_label>`'
            await self.say_error(ctx, error)
            return

        p = await Poll.load_from_db(self.bot, server.id, short)
        if p is not None:
            if p.options_reaction_default or p.options_reaction_emoji_only:
                error = f'Can\'t draw from emoji-only polls.'
                await self.say_error(ctx, error)
                return
            error = f'Insufficient permissions for this command.'
            if not await self.is_admin_or_creator(ctx, server, p.author.id, error_msg=error):
                return
            try:
                choice = ascii_lowercase.index(opt.lower())
            except ValueError:
                choice = 99
            if len(p.options_reaction) <= choice:
                error = f'Invalid answer "{opt}".'
                await self.say_error(ctx, error)
                return
            if p.open:
                await ctx.invoke(self.close, short=short)
            await p.load_full_votes()
            voter_list = []
            for vote in p.full_votes:
                if vote.choice == choice:
                    voter_list.append(vote.user_id)
            if not voter_list:
                error = f'No votes for option "{opt}".'
                await self.say_error(ctx, error)
                return
            # print(voter_list)
            winner_id = random.choice(voter_list)
            winner = server.get_member(int(winner_id))
            if not winner:
                error = f'Invalid winner drawn (id: {winner_id}).'
                await self.say_error(ctx, error)
                return
            text = f'The winner is: {winner.mention}'
            title = f'Drawing a random winner from "{opt.upper()}"...'
            await self.say_embed(ctx, text, title=title)
        else:
            error = f'Poll with label "{short}" was not found.'
            await self.say_error(ctx, error)
            await ctx.invoke(self.show) 
开发者ID:matnad,项目名称:pollmaster,代码行数:60,代码来源:poll_controls.py


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