我正在想办法让这些整数以行的形式显示,同时保持它们的顺序。在
但当我运行代码时,我得到的是显示。在
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
#
这就是我想看到的顺序 对应于范围整数。在
^{pr2}$这是我到目前为止的情况。在
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)
简单的重新排列:
相关问题 更多 >
编程相关推荐