python - 如何在第一个输入中打印?
问题描述
当我运行此代码时。
number = int(input())
collect = [] #collect number from input
for i in range(number):
x = int(input())
collect.append(x)
print(collect)
for j in [ele for ind, ele in enumerate(collect,1) if ele not in collect[ind:]]:
count = 0
for ele in collect:
if j == el:
count += 1
else:
pass
if count != 0:
print("{} : {} Items".format(ind, count))
else:
print("{} : {} Item".format(j, count))
**input:** 5
2
1
2
1
2
**output:**
5
2
1
2
1
2
[2, 1, 2, 1, 2]
1 : 2 Items
2 : 3 Items
我想展示
输出:
5
2
1
2
1
2
[2, 1, 2, 1, 2]
2 : 3 Items
1 : 2 Items
怎么做
解决方案
number = int(input())
print()
collect = [] #collect number from input
for i in range(number):
x = int(input("\n"))
collect.append(x)
print("\n\n" + str(collect))
y = [ele for ind, ele in enumerate(collect,1) if ele not in collect[ind:]]
y.reverse()
for j in y:
count = 0
for ele in collect:
if j == el:
count += 1
else:
pass
if count != 0:
print("\n{} : {} Items".format(ind, count))
else:
print("\n{} : {} Item".format(j, count))
推荐阅读
- scala - String 上的重载加 `+` 运算符
- python-3.x - 使用熊猫根据列中的值组合行
- vba - Excel VBA - 对多个表中行的所有修改的时间戳
- javascript - 如何使用组合图在条形图中创建连续线?
- python - 在elasticsearch_dsl中按特定属性分组时如何检索最后一个日志?
- jekyll - 如何在详细信息块中使用 Jekyll 中的 MathJax?
- python - Python:如何修复参数类型?
- java - Hibernate envers如何向审计表添加字段
- sql - 自定义颜色的 SQL 查询输出
- python-3.x - Python:请求在日期范围内抓取 Google 新闻不起作用