删除包含少于 3 个字符串的列表
remove lists containing less than 3 character strings
我有一个列表列表
list_of_lists = [['stringxyz', ','], ['WER', 'stringz'], ['F.7.T.', 'UZ'], ['WWW', 'stringy'], [None, ''], [None, 'Frahm']]
包含列表,包含 字符长度 <3 的字符串(请参阅上面的第一个和第三个列表)
我想从列表列表中删除这些列表
期望的输出:
list_of_lists = [['WER', 'stringz'], ['WWW', 'stringy']]
这个有效
# use any to check if any sub-list has None in it or has an element shorter than 3 characters
[s_l for s_l in list_of_lists if not (None in s_l or any(len(x)<3 for x in s_l))]
[['WER', 'stringz'], ['WWW', 'stringy']]
我有一个列表列表
list_of_lists = [['stringxyz', ','], ['WER', 'stringz'], ['F.7.T.', 'UZ'], ['WWW', 'stringy'], [None, ''], [None, 'Frahm']]
包含列表,包含 字符长度 <3 的字符串(请参阅上面的第一个和第三个列表)
我想从列表列表中删除这些列表
期望的输出:
list_of_lists = [['WER', 'stringz'], ['WWW', 'stringy']]
这个有效
# use any to check if any sub-list has None in it or has an element shorter than 3 characters
[s_l for s_l in list_of_lists if not (None in s_l or any(len(x)<3 for x in s_l))]
[['WER', 'stringz'], ['WWW', 'stringy']]