我向所有需要幫助的人打招呼,非常感謝
所以我有這個代碼
alphabet = {
"A": 1,
"á": 1,
"?": 1,
"?": 1,
"á": 1,
"a": 1,
"B": 2,
"b": 2,
"C": 3,
"?": 3,
"?": 3,
"c": 3,
"D": 4,
"d": 4,
"?": 4,
"?": 4,
"E": 5,
"é": 5,
"e": 5,
"é": 5,
"ě": 5,
"F": 6,
"f": 6,
"G": 7,
"g": 7,
"H": 8,
"h": 8,
"I": 9,
"i": 9,
"í": 9,
"í": 9,
"J": 10,
"j": 10,
"k": 11,
"K": 11,
"L": 12,
"l": 12,
"M": 13,
"N": 14,
"O": 15,
"ó": 15,
"P": 16,
"Q": 17,
"R": 18,
"?": 18,
"S": 19,
"T": 20,
"?": 20,
"?": 20,
"U": 21,
"V": 22,
"W": 23,
"X": 24,
"Y": 25,
"y": 25,
"m": 13,
"n": 14,
"ň": 14,
"o": 15,
"ó": 15,
"p": 16,
"q": 17,
"r": 18,
"?": 18,
"s": 19,
"?": 19,
"?": 19,
"t": 20,
"u": 21,
"ú": 21,
"ú": 21,
"?": 21,
"v": 22,
"V": 22,
"w": 23,
"x": 24,
"Y": 25,
"y": 25,
"z": 26,
"?": 26,
"Z": 26,
"?": 26,
"1": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"9": 0,
"0": 0,
",": 0,
".": 0,
",": 0,
":": 0,
"?": 0,
"=": 0,
" ": 0,
"-": 0,
"ˇ": 0,
"!": 0,
"?": 0,
"“": 0,
";": 0,
"?": 0,
"?": 0,
"\t": 0,
"'": 0,
"(": 0,
")": 0,
'"': 0,
'\n': 0,
"`": 0,
"′": 0,
" ": 0
}
def gematria(word):
result = 0
for char in word:
result = alphabet[char]
return result
with open('3.txt',encoding="utf8") as f:
line = f.readline()
while line:
line = f.readline()
print(gematria(line),line, file=open("" str("66") ".txt", "a",encoding="utf8"))
with open('66.txt',encoding="utf8") as infile, open('outpu.txt', 'w') as outfile:
for line in infile:
if not line.strip(): continue
outfile.write(line)
with open("outpu.txt", "r") as f:
lines = f.readlines()
with open("yourfile.txt", "w") as f:
for line in lines:
if line.strip("\n") != "0 ":
f.write(line)
并需要檔案檔案文本將數字排列在圖中的一行中
該腳本通過打開檔案 3.text 來作業,每一行都有類似的句子
輸入
11:1:2 Thank you for your help
11:1:1 and here is the text and the others continue the same lines
這個腳本吃掉了 da gematriie 并且需要在間隙排序方法之前對第一個進行排序,但我不知道該怎么做并將其保存到檔案中
輸出
553 11:1:1 and here is the text and the others continue the same lines
274 1:1:2 Thank you for your help
我希望它在空格之前從最小到最大的數字排序
274 1:1:2 Thank you for your help
553 11:1:1 and here is the text and the others continue the same lines
uj5u.com熱心網友回復:
讀取行并計算值,然后對它們進行排序并寫入檔案:
def gematria(word):
# using a "generator expression"
return sum(alphabet[char] for char in word)
with open('input.txt', encoding='utf8') as f:
# A generator expression that stores a sorted tuple of
# the calculation and the stripped line.
lines = sorted((gematria(line),line.strip()) for line in f)
with open('output.txt', 'w', encoding='utf8') as f:
for num,line in lines:
# Looks like you wanted to skip blank lines
if line:
print(num, line, file=f)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/462147.html
上一篇:在正則運算式上對python中的字串串列進行排序實際上并沒有排序
下一篇:通過改變元素的值對單鏈表進行排序
