0

我试图找出一种方法让这些整数在保持顺序的同时显示在行中。

但是当我运行代码时,这是我得到的显示。

Enter numbers 1... 22,34,35,40,55
Enter numbers 2... 12,14,34,47,49
Enter numbers 3... 1,4,10,19,30

Section 1             #
The number seqeuce is 0 between 0 and 9
The number seqeuce is 0 between 10 and 19
The number seqeuce is 1 between 20 and 29
The number seqeuce is 2 between 30 and 39
The number seqeuce is 1 between 40 and 49
The number seqeuce is 1 between 50 and 59
Section 2
The number seqeuce is 0 between 0 and 9
The number seqeuce is 2 between 10 and 19
The number seqeuce is 0 between 20 and 29
The number seqeuce is 1 between 30 and 39
The number seqeuce is 2 between 40 and 49
The number seqeuce is 0 between 50 and 59
Section 3
The number seqeuce is 2 between 0 and 9
The number seqeuce is 2 between 10 and 19
The number seqeuce is 0 between 20 and 29
The number seqeuce is 1 between 30 and 39
The number seqeuce is 0 between 40 and 49
The number seqeuce is 0 between 50 and 59
                      #

这是我希望看到的与范围整数相对应的顺序。

Enter numbers 1... 22,34,35,40,55
Enter numbers 2... 12,14,34,47,49
Enter numbers 3... 1,4,10,19,30
Section 1
The number seqeuce is 0 0 1 2 1 1 #
Section 2                         #
The number seqeuce is 0 2 0 1 2 0 # <-- Here is the sequennce from above
Section 3                         #
The number seqeuce is 2 2 0 1 0 0 #

这是我到目前为止所拥有的。

import collections  

the_inputs = [] 

for i in range(3): 
    the_inputs.append(raw_input("Enter numbers {}... ".format(i+1))) 

the_lists = [] 

for the_input in the_inputs: 
    the_lists.append([int(x)//10 for x in the_input.strip("[]").split(",")]) 

for i, the_list in enumerate(the_lists): 
    print "Section {}".format(i+1) 
    group_counter = collections.Counter(the_list) 
    bin_range = range (6)  
    for bin_tens in bin_range:
        print "The number seqeuce is {} between {} and {}".format(group_counter[bin_tens], bin_tens*10, bin_tens*10+9)
4

1 回答 1

1

一个简单的重新排列:

print "The number sequence is",
for bin_tens in bin_range:
    print group_counter[bin_tens],
print
于 2012-09-01T19:12:33.503 回答