python - 打印出现两次的连续数字?

标签 python

我想在Python中打印出每个项目并连续编号,但每个数字应该出现两次。

1 Item
1 Item
2 Item
2 Item
3 Item
3 Item

最佳答案

items = ['Item'] * 6
for i, item in enumerate(items, start=1):
    number = (i + 1) / 2
    print('{} {}'.format(number, item))

关于python - 打印出现两次的连续数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30781335/

相关文章:

python - 如何匹配文本和可选的重复标识符并将它们组合在一起?

python - 我的 python 函数有什么问题?

python - Celery - Heroku 上带有 Celery 工作进程的 Django Web 应用程序 - 我该如何追查此内存泄漏?

python - 在 Firebase 函数中使用 Google Cloud AutoML 模型预测存储在 Google Cloud 存储中的图像

python - 退出 root conda 环境

python - 属性错误: 'WSGIRequest' object has no attribute 'getlist'

python - 如何在 Python zlib 模块中设置参数

python - 带有 PTVS 的 Anaconda - "conda list"与 "pip list"和 PTVS 不同

python - Django LazyUser 代码如何工作?

python - "Django-insecure"在 Django 的 settings.py 中的 key 中