【每日一题20220328】数字膨化

:man_mage: 给定一个由[0-9]数字组成的字符串,请编写一个函数,将其中每个数字,按照它字面值重复,返回最终的字符串。

实例:
输入:"312"
输出: "333122"
解释:第一位是3,因此变成3个3; 第二位是1,因此变成1个1;第三位是2,因此变成2个2。

题目难度:简单
题目来源:CodeWars:Digits explosion

def solution(s: str) -> str:
    # your code here

assert solution("312") == "333122"
assert solution("000") == ""
assert solution("102269") == "12222666666999999999"
def explode(s):
    return ''.join(x*int(x) for x in s)
1 Like
def solution(s: str) -> str:
    # your code here
    return ''.join(i * int(i) for i in s)

def solution(s: str) → str:
a = " "
a = a.join(value*int(value) for value in s)
return a
print(solution(“445”))

    def solution(s: str) -> str:
        return ''.join([i for i in s for j in range(int(i))])

def solution(a: str):
result = “”
for i in a:
result += i * int(i)
return result


def solution(s: str) -> str:
    return ''.join(i*int(i) for i in s)
str1 ='312'
str2=''
for i in str1:
    for j in range(int(i)):
        str2 += str2.join(i)
print(str2)

solution=lambda s:‘’.join([i*int(i) for i in s])

‘’.join(list(filter(None,map(lambda x:int(x)*x if int(x)!=0 else None,list(‘31’)))))

def solution(s: str) → str:
# your code here
w =
for z in range(0, len(s)):
for q in range(int(s[z])):
w.append(str(s[z]))
return ‘’.join(w)

str_list = [x for x in s]
s = ''
for i in str_list:
    s = s + (''.join([i*int(i)]))
return s
def solution(s: str) -> str:
    return "".join([int(i) * i for i in list(s)])

assert solution("312") == "333122"
assert solution("000") == ""
assert solution("102269") == "12222666666999999999"
def solution(s: str) -> str:
    return ''.join([i*int(i) for i in s])


assert solution("312") == "333122"
assert solution("000") == ""
assert solution("102269") == "12222666666999999999"
def solution(s: str) -> str:
    return ''.join([s[i] * int(s[i]) for i in range(len(s))])


assert solution("312") == "333122"
assert solution("000") == ""
assert solution("102269") == "12222666666999999999"