+ 1

How to find same alphabets twice or more in a word?

Like in chocolate No. of c = 2 No. Of o = 2

5th May 2020, 1:00 PM
Sagun Karki
Sagun Karki - avatar
3 odpowiedzi
+ 2
Please show us your attempt..
5th May 2020, 1:14 PM
ANJALI SAHU
+ 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
5th May 2020, 1:40 PM
Sagun Karki
Sagun Karki - avatar
+ 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🙂
5th May 2020, 2:06 PM
ANJALI SAHU