我正在尝试将特定的 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/