转换为while循环

时间:2015-09-14 12:02:12

标签: python loops converter

有人知道如何将其转换为while循环吗?

def function(number):
   dictionary_num = {}
   for i in number:
     if i in dictionary_num:
      dictionary_num[i] += 1
     else:
      dictionary_num[i] = 1

1 个答案:

答案 0 :(得分:1)

技术答案:

def whloop(numbers):
    d = {}
    numbers = list(numbers)
    while numbers:
        i = numbers.pop()
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d

但这样做真的没有意义......