相关疑难解决方法(0)

如何生成解压扩展程序的Chrome扩展程序ID?

我想与同事分享一个解压缩的扩展程序.它chrome.runtime.sendMessage(string extensionId, any message, object options, function responseCallback)在注入的脚本中使用该方法.为此,我需要提前知道扩展ID.

解包扩展程序的扩展ID在不同系统上是否会有所不同,或者我可以对我在扩展菜单中找到的扩展ID进行硬编码?

google-chrome-extension

5
推荐指数
1
解决办法
2053
查看次数

如何使用 Python 在输入字符串中移动元音

我正在尝试编写一个函数,让我可以移动字符串中的单个字母。字符串来自输入。

我在看元音所以“a,e,i,o,u”

我希望将单个字母向右移动一位。即世界“m e ”将成为“m i ”,因为ie之后的下一个字母。

这是我到目前为止:

import random
vowels = ("a", "e", "i", "o", "u")

message = input("Enter a string")

new_message = ""

for letter in message:
    if letter not in vowels:
        new_message += letter
    else:
        new_message += random.choice(vowels)
        
print(new_message)
Run Code Online (Sandbox Code Playgroud)

然而,这会使单个元音的变化随机化,使其转移到下一个字母的最佳方法是什么?

python string

4
推荐指数
1
解决办法
283
查看次数

在python中按某个值移动字母

我有一个编码文本文件,它通过简单的字母转换进行编码。我现在已将其中的信息分成两个列表。在这种格式中:

list_1 =['fjsir', 'vnjk', 'eioafnvjf', 'einbvfbj']
list_2 =[3,4,7,1]
Run Code Online (Sandbox Code Playgroud)

第二个列表是字母表中应该移动多少个位置。例如。如果列表一中的索引 0 具有'fjsir'并且其对应的索引list_2为 3,则它将解码为'cfpeo'. 我不确定如何在 python 中匹配这些。

python

3
推荐指数
2
解决办法
2万
查看次数

将字符串中的每个字符更改为字母表中的下一个字符

我在 Ubuntu 上使用 PyCharm 在 Python 2.7 中编码。

我正在尝试创建一个函数,该函数将接受一个字符串并将每个字符更改为字母表中的下一个字符。

def LetterChanges(str):
    # code goes here
    import string
    ab_st = list(string.lowercase)
    str = list(str)
    new_word = []
    for letter in range(len(str)):
        if letter == "z":
            new_word.append("a")
        else:
            new_word.append(ab_st[str.index(letter) + 1])
        new_word = "".join(new_word)
    return new_word


# keep this function call here
print LetterChanges(raw_input())
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,出现以下错误:

/usr/bin/python2.7 /home/vito/PycharmProjects/untitled1/test.py
test
Traceback (most recent call last):
  File "/home/vito/PycharmProjects/untitled1/test.py", line 17, in <module>
    print LetterChanges(raw_input())
  File "/home/vito/PycharmProjects/untitled1/test.py", line 11, in LetterChanges
    new_word.append(ab_st[str.index(letter) + 1])
ValueError: 0 …
Run Code Online (Sandbox Code Playgroud)

python string python-2.7

2
推荐指数
1
解决办法
2万
查看次数

当索引超出范围时如何再次循环列表

您好,我正在尝试一个简单的密码程序,该程序将按用户输入的值移动字母,但是,当该单词包含字母“z”时,它将抛出索引超出范围的错误。因此,为了解决这个问题,我尝试了复制列表的简单方法,但我想使用更好的方法来做到这一点。我想检查索引是否超出范围,然后再次循环列表并执行与代码中所示相同的任务非常感谢!

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))

def encrypt(plain_text, shift_amount):
  cipher_word = ""
  indexed_letter = len(alphabet)
  for letter in plain_text:
    position = alphabet.index(letter)
    new_position = position + shift_amount
    new_letter = alphabet[new_position]
    cipher_word += new_letter
    
    if …
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
1
解决办法
961
查看次数

如何以Pythonic方式将"ABCD ..."转换为"CDEF ..."?

例如,我有一个lst = "ABCXYZ",我希望输出"CDEZAB"

我到目前为止提出的最佳方法是:

"".join(chr((ord(x)-ord('A')+2)%26+ord('A')) for x in lst)
Run Code Online (Sandbox Code Playgroud)

哪个很尴尬.使用字典{'A': 'C', 'B': 'D', ……, 'X': 'Z', 'Y': 'A', 'Z': 'B'}似乎更像Pythonic,但更尴尬.

有任何想法吗?

python string algorithm ascii python-3.x

0
推荐指数
1
解决办法
179
查看次数

按某个步骤移动字符串的所有字母

  • 输入:['baNaNa', 7] #字符串和步长
  • 所需的输出:'utGtGt'# 字符串的每个字符按步长向后移动
import ast  
in_string = input()  
lis = ast.literal_eval(in_string)  
st = lis[0]  
step = lis[1]  
alphabets = 'abcdefghijklmnopqrstuvwxyz'  
password = ''  
for letter in st:  
    if letter in alphabets:  
        index_val = alphabets.index(letter) - (step)  
        password += alphabets[index_val]  

print(password)
Run Code Online (Sandbox Code Playgroud)

我得到的输出是“utgtgt”。我想要'utGtGt'。对此的帮助将不胜感激。

python string indexing loops python-3.x

0
推荐指数
1
解决办法
396
查看次数

凯撒密码问题

我正在尝试实施一个凯撒密码.

我试图在函数中返回消息,但是我收到一条错误消息(外部函数).有人可以帮忙吗?

提前致谢

cat
cate
catec
catecv

message = input("type message ")

shift = int(input("Enter number to code "))
message = message.lower() #convets to lower case
print (message)

for a in message:
    if a in "abcdefghijklmnopqrstuvwxyz":
        number = ord(a)
        number += shift
        if number > ord("z"):
            number -= 26
        elif number < ord("a"):
             number += 26
        message = message + (chr  ( number))

    print (message)
Run Code Online (Sandbox Code Playgroud)

python caesar-cipher

-1
推荐指数
1
解决办法
1172
查看次数

两个字符串,并让输入的字母打印另一个字符串中的内容

不确定标题是否有意义或真的如何表达问题,但我试图做的是用户每次输入一个句子,然后它会根据该字母的任何索引从另一个字符串中抓取和将其打印到新字符串,然后打印字符串。

可能是一种更简单的方法,但是如果您能以这种方式进行解释并且更简单的方式会很酷,那么您一旦看到代码就会理解。

abc = "abcdefghijklmnopqrstuvwxyz"
caesar_cipher="bcdefghijklmnopqrstuvwxyza"
user = input("Enter what you want ciphered: ")
new_string = ''




print(new_string)
Run Code Online (Sandbox Code Playgroud)

python string input python-3.x

-1
推荐指数
1
解决办法
42
查看次数