String 尝试更改python中列表的格式

String 尝试更改python中列表的格式,string,list,python-3.x,substring,String,List,Python 3.x,Substring,我有点像 [['b c', 'd e', 'f'], ['b', 'c', 'd', 'e', 'f'], ['b c', 'd', 'b', 'e', 'g', 'f']] 但我想把这个改成 ['(b c) d e f', 'b c d e f', '(b c) d b e g f'] 我试过几种不同的方法,但括号把我的方法弄乱了。我能够在没有括号的情况下连接字符串。在python中有什么简单的方法可以做到这一点吗?这对我来说很有用: new_list = [" ".join(words

我有点像

[['b c', 'd e', 'f'], ['b', 'c', 'd', 'e', 'f'], ['b c', 'd', 'b', 'e', 'g', 'f']]
但我想把这个改成

['(b c) d e f', 'b c d e f', '(b c) d b e g f']
我试过几种不同的方法,但括号把我的方法弄乱了。我能够在没有括号的情况下连接字符串。在python中有什么简单的方法可以做到这一点吗?

这对我来说很有用:

new_list = [" ".join(words if not " " in words else "({})".format(words) for words in seq)  for seq in original_list]
但是假设括号的逻辑是,只要字符串中有一个空格被连接,就会添加括号。但这意味着你的例子是错误的。如果parentheres只应添加到每个子列表的第一个字符串中,则必须在条件列表中包含计数:

new_list = [" ".join(words if not " " in words and i == 0 else "({})".format(words) for i, words in enumerate(seq))  for seq in original_list]

什么样的逻辑决定了括号什么时候应该出现,什么时候不应该出现?我特别困惑为什么
de
没有在第一个列表中括起来。在第一个子列表中,不清楚为什么
(b c)
在括号中,而不是
de