我的代碼是關於用每個單詞/數字的第一個字符/數字作爲一個句子/短語中的一個字符來創建一個密碼,並且就像這樣打印它。Python:把第一個字符沒有列表
示例:停下來嗅到350朵「玫瑰花」。 - > Sast3r。 (忽略使用用r 報價)
這將是非常容易使用列表,但你不能在這個分配使用它們我的代碼。所以,我不知道要什麼有什麼我迄今所做的後現在要做的
功能:
def create_password(phrase):
q = "'" # quotations
dq = '"' # double quotes
password = phrase[0]
for i in phrase:
x = phrase.find(" ")
if i.isalnum:
password += phrase[x + 1]
elif x == q or x == dq:
password += phrase[x + 2]
return password
主營:
# Imports
from credentials import create_password
# Inputs
phrase = str(input("Enter a sentence or phrase: "))
# Outputs
password = create_password(phrase)
print(password)
字符串與字符列表幾乎相同。幾乎所有可以用列表完成的事情都可以用字符串來完成。 –
我認爲你到目前爲止在正確的軌道上。當我第一次看到你的問題時,我立即想到了'.find',這似乎就是你以後的想法。然而,'.find()'有第二個參數,它告訴你在什麼點開始尋找之後。 – Zizouz212
你總是可以使用迭代器:'l ='abc''然後'next(iter(l))'會給你'a'; – Marcin