python - 打印由任何字符而不是逗号分隔的列表项 (Python)

标签 python list

我正在尝试将特定的 length 分成 sections 并打印 section division_result times in row。剩下的除以2,分别放在链表的开头和末尾。
现在我有这个:

section = 180
length_to_divide: int = 2150
interject = ' X '

division_result = length_to_divide / section
sides = (length_to_divide % section) / 2
whole = str(section).split() * int(division_result)
print(sides, whole, sides)

输出

85.0 ['180', '180', '180', '180', '180', '180', '180', '180', '180', '180', '180'] 85.0

有什么方法可以按行打印列表项,但在我的例子中,用逗号分隔 interject = ' X ',我想要这样的输出:

85.0 X 180 X 180 X 180 X 180 X 180 X 180 X 180 X 180 X 180 X 180 X 180 X 85.0

最佳答案

另一种选择:

section = 180
length_to_divide: int = 2150
sides = str((length_to_divide % section) / 2)
whole = str(section).split() * int(length_to_divide / section)
s = ' X '.join([sides, *whole, sides])
print(s)

关于python - 打印由任何字符而不是逗号分隔的列表项 (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64173626/

相关文章:

python - Bokeh 中具有紧密轴和匹配纵横比的图像图

java - 过滤列表的组件

java - 为自定义对象列表实现 removeAll 的问题

c# - 在 C# 中将字典转换为列表集合

python - CouchDB-Python:如何使用 “_show” 和 “_list” 函数?

python - 如何在 sklearn 中对不平衡数据集进行交叉验证

python - python pd.DataFrame( {'Dokuman' : docs, 'Sinif' : 类}) 中的 Pandas 数据框问题

python - 堆积条形图求和特征值

斯卡拉。获取 List 的第一个元素

python - 返回第三列处具有最大值的子列表的第一项