行在列表中重复 python
lines repeat in List python
下一个问题我需要你的帮助,
我需要 python 接收字符串“EEEEDDSGES”,输出将由重复的字符总和组成,
E 4
2
1
1
1
S 1
下一个是我的代码,
diccionario = {}
contador = 0
for palabra in cadena:
if palabra.upper() in diccionario:
diccionario[palabra.upper()] += 1
else:
diccionario[palabra.upper()] = 1
for palabra in diccionario:
frecuencia = diccionario[palabra]
print(palabra, end=" ")
print(frecuencia) ```
the output is ,
S,S,d,f,s
S 1
S 2
d 3
f 4
s 5
抱歉,我不明白这种语言是什么,但我想我明白你想做什么。为了理解,我更改了变量名称。
s="EEEEDDSGES"
letters={}
for i in s:
i=i.upper()
try:
letters[i]+=1
except(KeyError):
letters.update({i:1})
for i in letters: print(f"{i}: {letters[i]}", end=" ")
from itertools import groupby
s = "EEEEDDSGES"
for v, g in groupby(s):
print(v, sum(1 for _ in g))
打印:
E 4
D 2
S 1
G 1
E 1
S 1
下一个问题我需要你的帮助, 我需要 python 接收字符串“EEEEDDSGES”,输出将由重复的字符总和组成, E 4 2 1 1 1 S 1
下一个是我的代码,
diccionario = {}
contador = 0
for palabra in cadena:
if palabra.upper() in diccionario:
diccionario[palabra.upper()] += 1
else:
diccionario[palabra.upper()] = 1
for palabra in diccionario:
frecuencia = diccionario[palabra]
print(palabra, end=" ")
print(frecuencia) ```
the output is ,
S,S,d,f,s
S 1
S 2
d 3
f 4
s 5
抱歉,我不明白这种语言是什么,但我想我明白你想做什么。为了理解,我更改了变量名称。
s="EEEEDDSGES"
letters={}
for i in s:
i=i.upper()
try:
letters[i]+=1
except(KeyError):
letters.update({i:1})
for i in letters: print(f"{i}: {letters[i]}", end=" ")
from itertools import groupby
s = "EEEEDDSGES"
for v, g in groupby(s):
print(v, sum(1 for _ in g))
打印:
E 4
D 2
S 1
G 1
E 1
S 1