[英]How to create a string from elements in tuples in a list
Is there a more succinct way to do this?有没有更简洁的方法来做到这一点?
MyList = [(1,2,3),(6,6,7)] # example
msg = "";
for (a,b,c) in MyList:
msg += str(b)
Yes, join
.是的,
join
。
str_msg = "".join([str(b) for (a,b,c) in MyList])
Where the starting quotes contain any delimiter you might want to use between elements and where MyList
is some collection of string items.其中起始引号包含您可能希望在元素之间使用的任何分隔符,而
MyList
是一些字符串项的集合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.