我创建了一个小程序来输出Name char和char的位置,但是它没有按我的预期工作。
收益不返回任何内容,而Return语句仅返回char和num列表的最后一个值。
name_letters = "Alexi Rodrigo"
def get_number():
for number in xrange(1, len(name_letters)+1):
yield number
def letters_list():
for letter in name_letters:
yield letter
print " "
print "======================"
print " "+" "+"Text w/ Numbers"
print "======================"
print " "
output_text = get_number(), letters_list()
print output_text
## Output should be Letter + Position Number
答案 0 :(得分:0)
为什么不尝试关注...
for n, c in enumerate(name_letters):
print n, c
如果您不想对空间进行编号
name_letters = "Alexi Rodrigo"
n = 0
for c in name_letters:
if c != ' ':
print n, c
n += 1
else:
print c