+ 1
How to find same alphabets twice or more in a word?
Like in chocolate No. of c = 2 No. Of o = 2
3 ответов
+ 2
Please show us your attempt..
+ 1
a = "chocolate"
b = list(a)
for i in range(len(b)):
c = 0
for j in range(len(b)):
if b[i] == b[j]:
c += 1
print(b[i],c)
i did this, it counted the elements but printed the elements twice
i also wanted to find the duplicates location in the string like c = [0,3] but i have no any idea
could you please help me out
+ 1
a = "chocolate"
b = list(a)
l=[]
for i in range(len(b)):
c = 0
for j in range(len(b)):
if b[i] == b[j]:
c += 1
if c>1:
x=[r for r in range(len(a)) if b[i]==b[r]]
else:
x=[i]
l.append((b[i],c,x))
new=[]
for i in l:
if i not in new:
new.append(i)
print(i)
Please take help from this code..please run it.and I think you get your desired output🙂