使用python如何让我看起来像这个dooggg,所以每个字母再次重复。我尝试过这样的东西
# Program 21
def double(source):
pile = ""
for letter in source:
pile = pile+letter+letter
print pile
print pile
但看起来像是
dd
ddoo
ddoogg
答案 0 :(得分:1)
"".join(l*i for i,l in enumerate(my_word,1))
我认为应该这样做
答案 1 :(得分:1)
...试
performOnCommunicationQueue
如果你想在一行上全部试试这个用于python 2:
def double(source):
word = []
for x in range(len(source)):
word.append(source[x]*(x+1))
print ''.join(map(str, word))
double("dog")
input()
这对于python 3:
def double(source):
word = []
for x in range(len(source)):
word.append(source[x]*(x+1))
print ''.join(map(str, word)),
double("dog")
input()