将一个while循环转换为Python中的for循环3.3

问题描述:

我试图将while循环转换为for循环,但我不知道如何去做。将一个while循环转换为Python中的for循环3.3

output = '' 
i = 0 
while i <len(MyArray): 
    C = chr(int(MyArray[i],2)) 
    output = output + C 
    i = i + 1 

print(output) 

任何帮助,将不胜感激

output = '' 
for i in range(len(MyArray)): 
    C = chr(int(MyArray[i],2)) 
    output = output + C 

print(output) 

output = '' 
for element in MyArray: 
    C = chr(int(element,2)) 
    output = output + C 

print(output) 

output = [chr(int(element,2)) for element in MyArray] 
print ''.join(output) 
+0

嗨,其未来与那个时候我有输出没有定义的错误试过你的解决方案 – user3250858

+0

是的,它走了在复制你的代码时丢失了,但它应该是相当明显的如何解决这个问题:) –

+0

哈哈我的错,是的人其完美的感谢! – user3250858