Problem :

https://leetcode.com/problems/count-and-say/description/


My Solution :

class Solution:
def countAndSay(self, n):
"""
:type n: int
:rtype: str
"""
before = [1]
for _ in range(1, n):
result = []
count = 1
for i in range(1, len(before)):
if before[i] == before[i-1]:
count += 1
else:
result.extend([count, before[i-1]])
count = 1
result.extend([count, before[-1]])
before = result
return ''.join(map(str, before))