在python中是否可以从集合中丢弃数字字符串(字符串仅包含数字)?

在python中是否可以从集合中丢弃数字字符串(字符串仅包含数字)?,python,set,Python,Set,例如,这套设备是: {'abc', '123', 'efg', 'er23'} 我只想从片场中去掉‘123’。在python中可能吗?试试: s={'abc', '123', 'efg', 'er23'} print({i for i in s if not i.isdigit()}) 尝试: 您好,您可以这样做,这将只删除元素,只有数字 data = {'abc', '123', 'efg', 'er23'} new_items = [item for item in data if no

例如,这套设备是:

{'abc', '123', 'efg', 'er23'}
我只想从片场中去掉‘123’。在python中可能吗?

试试:

s={'abc', '123', 'efg', 'er23'}
print({i for i in s if not i.isdigit()})
尝试:


您好,您可以这样做,这将只删除元素,只有数字

data = {'abc', '123', 'efg', 'er23'}
new_items = [item for item in data if not item.isdigit()]
print new_items 

您好,您可以这样做,这将只删除元素,只有数字

data = {'abc', '123', 'efg', 'er23'}
new_items = [item for item in data if not item.isdigit()]
print new_items 

{s for s in your_set if not isinstance(s,int)}
是一种方法。@Maroun
isinstance
不会工作,因为项是字符串。@Xnkr你说得对,谢谢。
{s for s in your_set if not isinstance(s,int)}
是一种方法。@Maroun
isinstance
不会工作,因为项是字符串。@Xnkr你说得对,谢谢。这很好,但是仍然应该转换为
set
这个工作,但是仍然应该转换为
set