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