我需要一条'一线' Python语句,它生成一个元组,只包含带有' @'的字符串。在他们中间。
Input:
tuple_1 = ('asdf@', 'asdf') #the given (not included in the 2 lines)
for string in tuple_1:
if '@' in string: tuple_2 = (string)
Out:
tuple_2 = ('asdf@')
答案 0 :(得分:1)
经过几次试训,我刚刚解决了这个问题:
tuple_1 = ('asdf@', 'asdf')
tuple_2 = ()
for elem in [item for item in tuple_1 if '@' in item]: tuple_2 = tuple_2 + (elem,)
print tuple_2
我希望这就是你所需要的!我投票给你了,因为这让我想起了大学里数学自学时光的一点点乐趣。