Solving Accenture Data Engineer Interview Question | Count of each alpha in strings in Python |
Вставка
- Опубліковано 20 сер 2024
- Combo course package : www.geekcoders...
I have prepared many courses on Azure Data Engineering
1. Build Azure End to. End Project
www.geekcoders...
2. Build Delta Lake project
www.geekcoders...
3. Master in Azure Data Factory with ETL Project and PowerBi
www.geekcoders...
4. Master in Python
www.geekcoders...
Check out my courses on Azure Data Engineering
www.geekcoders...
hastags
tags
#dataengineer #interviewquestions #python
#hashtags #hastag #tags #tcs
Hi Sagar! Thanks for the content my approach
d={}
for i in Input:
if i in d:
d[i]=d[i]+1
else:
d[i]=1
print(list(d.values()))
Using Dictionary:
s='bbbbcccaad'
freq={}
for key in s:
if key in freq.keys():
freq[key]+=1
else:
freq[key]=1
print(list(freq.values()))
Good solution
from collections import Counter
input="bbbbcccaad"
ans=Counter(input)
print(ans.values())
D={}
Output=' '
For ch in input :
D[ch]=D.get(ch,0)+1
For k,v in D.items():
Output =output+ int(v)
Print(output)
12:52 happiness after successfully running the code😂❤
Hahahah
I think using set and dictionary(from_keys) is also good one to solve this issue like that.
st = 'bbbbaaccc'
keys = set(list(st))
dc = dict.fromkeys(keys,0)
for i in dc.keys():
for j in st:
if i == j:
dc[i]=dc[i] + 1
print(dc)
@@VITTHALPATIDAR-l1p yes thanks
We can use a dictionary too
map = {}
res=[]
for i in input:
map[i] = map.get(i, 0) + 1
for (_,v) in map.items():
res.append(v)
print(res)
inputString:str = "bbbbcccaad"
list({letter:inputString.count(letter) for letter in inputString}.values())
Output :
[4, 3, 2, 1]
Wonderful
string = "aaaabbbccd"
def EveryAlpha(string):
count = {}
for i in string:
if i in count:
count[i] += 1
else:
count[i] = 1
return list(count.values())
print(EveryAlpha(string))
input="bbbbcccaad"
#output=[4,3,2,1]
def count(input):
dict={}
for i in input:
if i in dict:
dict[i]+=1
else:
dict[i]=1
return list(dict.values())
print(count(input))
input='bbbbcccaad'
output_list=[]
for i in input:
if input.count(i) in output_list:
pass
else:
output_list.append(input.count(i))
print(output_list)
dictr = {}
str1 = "bbbbcccaad"
n = len(str1)
for i in range(n):
dictr[str1[i]]=0
p1=0
p2 =0
for k in range(n):
if str1[p1] == str1[p2]:
dictr[str1[p1]] = dictr[str1[p1]]+1
p1 = p1+1
p2 = p2+1
else:
p1 = p1+1
p2 = p2+1
Best he bhai 👍
Hey brother I'm getting stuck how to learn string and array in python for interview.
Can you guide me any content?
Bro, you're confusing yourself and us both. please stop.
@@nirmitgupta3941 ok sir
really sorry, did not mean to demotivate you. What you're doing is really commendable and takes lot of guts and hardwork.
In this specific video, it looked like you're yourself trying to find a solution by trying different things and taking a difficult approach for an easy question.
It owuld make much more sense if you figure out the solution yourself before recording.
Please take this as a suggestion.
Kudos to you and keep up the good work. ❤
@@nirmitgupta3941 np sir, I didnt mind. I took as positive only. The reason is I don’t make a script before any video. We all are coders we all should know where we can do a mistakes
Maybe coz he's not a very experienced guy but has only few years like a fresher
s='bbbbcccaad'
l=[]
rs=[]
for i in s:
if i not in rs:
rs.append(i)
for i in rs:
l.append(s.count(i))
print(l)
simply and easy
input='aaaabbbccd'
#iterate through the string and count each alpha using dict and then convert to list
str_dict={}
#looping through input
for i in input:
if i in str_dict:
str_dict[i]+=1
else:
str_dict[i]=1
print(str_dict)
#To get list
list_out=[]
for (ch,value) in str_dict.items():
list_out.append(value)
print(list_out)
@@umakamatchi8249
l='aaaabbbccd'
d={i:l.count(i) for i in l}
print(list(d.values()))