题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
import re text = input() num = [] word = [] s = "" for i in re.split("[^0-9]", text): if len(i) != 0: num.append(i) for i in re.split("[0-9]", text): if len(i) != 0: word.append(i) if text.isnumeric(): s = "*" + text + "*" elif text.isalpha() and not text.isnumeric(): s = text else: for i in range(min(len(num), len(word))): if text[0].isnumeric(): s = s + "*" + num[i] + "*" + word[i] else: s = s + word[i] + "*" + num[i] + "*" if len(word) > len(num): s = s + word[-1] elif len(num) > len(word): s = s + "*" + num[-1] + "*" print(s)