Here I am counting each character in a string and return that character with it's number of occurences in the string. e.g.: ab("aabbc")
and return a string: a2b2c1
However I have a list here where instead of returning a2b2c1
, it returns ['a',2,'b',2,'c',1]
. I want it to return it in the form of a string, and not a list.
Here's what I did:
def ab(n):
char = []
for i in n:
if i not in char:
char.append(i)
count = n.count(i)
char.append(count)
return(char)