作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要打印整数的排序列表,但它应该在一行中,没有列表方括号,最后没有任何 '\n'...
import random
n = int(input(""))
l=[]
for i in range(n):
x = int(input())
l.append(x)
not_sorted = True
while not_sorted:
x = random.randint(0,n-1)
y = random.randint(0,n-1)
while x==y:
y = random.randint(0,n-1)
if x>y:
if l[x]<l[y]:
(l[x],l[y])=(l[y],l[x])
if x<y:
if l[x]>l[y]:
(l[x],l[y])=(l[y],l[x])
for i in range(0,n-1):
if l[i]>l[i+1]:
break
else:
not_sorted = False
for i in range(n):
print(l[i])
最佳答案
您可以将列表解压到 print
使用 *
这将自动被一个空格分割
print(*l)
sep=
争论
print(*l, sep=', ')
关于python - 如何在一行中打印列表元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52097264/
我是一名优秀的程序员,十分优秀!