我想从以下列表中获取唯一值:
['nowplaying', 'PBS', 'PBS', 'nowplaying', 'job', 'debate', 'thenandnow']
Run Code Online (Sandbox Code Playgroud)
我需要的输出是:
['nowplaying', 'PBS', 'job', 'debate', 'thenandnow']
Run Code Online (Sandbox Code Playgroud)
此代码有效:
output = []
for x in trends:
if x not in output:
output.append(x)
print(output)
Run Code Online (Sandbox Code Playgroud)
我应该使用更好的解决方案吗?
是否有一种简短的方法来删除包含数字的列表中的所有字符串?
例如
my_list = [ 'hello' , 'hi', '4tim', '342' ]
Run Code Online (Sandbox Code Playgroud)
会回来的
my_list = [ 'hello' , 'hi']
Run Code Online (Sandbox Code Playgroud) python ×2