是否有逗号介于成语之间? [英] Is there a commas-in-between idiom?
问题描述
嗨专家,
我有一个列表很常见,我想用逗号打印它们之间的间隔是
。我怎么这么简单地做到这一点,最后没有
烦人的逗号?
< code>
>
list = [1,2,3,4,5,6]
#简单方法
列表中的元素:
打印元素,'','',
打印
#这就是我真正想要的。有没有更好的方法?
if(len(list)0):
打印列表[0],
列表中的元素[ 1:]:
打印'','',元素,
< / code>
Thx,
Ernesto
ErnestoGarcíaGarcía< ti ************ **********@gmail.com写道:
嗨专家,
它是'很常见,我有一个列表,我想用逗号打印它
介于两者之间。我怎样才能以一种简单的方式做到这一点,最终没有
烦人的逗号?
>> list = [1,2,3,4 ,5,6]
print'',''。join(map(str,list))
1 ,2,3,4,5,6
-
Christian Joergensen | Linux,编程或网络咨询
http://www.razor.dk |请访问我们的网站: http://www.gmta.info
ErnestoGarcíaGarcía写道:
我有一个列表很常见,我想用逗号打印它介于两者之间的
。我怎样才能以一种简单的方式做到这一点,最终没有
烦人的逗号?
>> items = [1,2,3," ;很多]
打印"," .join(项目中项目的str(项目))
1,2,3,很多
Peter
ErnestoGarcíaGarcía写道:
嗨专家,
我有一个列表很常见,我想用逗号打印它
介于两者之间。我怎么这么简单地做到这一点,最后没有
烦人的逗号?
< code>
>
list = [1,2,3,4,5,6]
#简单方法
列表中的元素:
打印元素,'','',
打印
#这是我真正想要的。有没有更好的方法?
if(len(list)0):
打印列表[0],
列表中的元素[ 1:]:
打印'','',元素,
< / code>
Thx,
Ernesto
print"," .joint(some_list)
您所命名的列表的位置现在被称为some_list因为重新分配内置类型的名字是非常不明智的。
James
>
Hi experts,
it''s very common that I have a list and I want to print it with commas
in between. How do I do this in an easy manner, whithout having the
annoying comma in the end?
<code>
list = [1,2,3,4,5,6]
# the easy way
for element in list:
print element, '','',
print
# this is what I really want. is there some way better?
if (len(list) 0):
print list[0],
for element in list[1:]:
print '','', element,
</code>
Thx,
Ernesto
Ernesto García García <ti**********************@gmail.comwrites:
Hi experts,
it''s very common that I have a list and I want to print it with commas
in between. How do I do this in an easy manner, whithout having the
annoying comma in the end?
>>list = [1,2,3,4,5,6]
print '',''.join(map(str, list))
1,2,3,4,5,6
--
Christian Joergensen | Linux, programming or web consultancy
http://www.razor.dk | Visit us at: http://www.gmta.info
Ernesto García García wrote:
it''s very common that I have a list and I want to print it with commas
in between. How do I do this in an easy manner, whithout having the
annoying comma in the end?
>>items = [1, 2, 3, "many"]
print ", ".join(str(item) for item in items)
1, 2, 3, many
Peter
Ernesto García García wrote:Hi experts,
it''s very common that I have a list and I want to print it with commas
in between. How do I do this in an easy manner, whithout having the
annoying comma in the end?
<code>
list = [1,2,3,4,5,6]
# the easy way
for element in list:
print element, '','',
# this is what I really want. is there some way better?
if (len(list) 0):
print list[0],
for element in list[1:]:
print '','', element,
</code>
Thx,
Ernestoprint ",".joint(some_list)
Where what you have named "list" is now called "some_list" because it is
terribly ill-advised to reassign the name of a built-in type.
James
这篇关于是否有逗号介于成语之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!