从元组中提取清单
我希望从Python的Tuple即时创建一个唯一的列表(例如设置值)。有办法做到吗?
ip_addrs_with_ports = [('192.168.1.1', '1234'),('192.168.1.1', '1235'),('192.168.1.3', '1236')]
我不想迭代列表,以获取IP地址值。有什么办法可以直接获得IP地址,类似的东西。
ip_addr = ['192.168.1.1','192.168.1.3']
I am looking to create a unique list (like set values) on the fly from tuple in python. Is there a way to do it.
ip_addrs_with_ports = [('192.168.1.1', '1234'),('192.168.1.1', '1235'),('192.168.1.3', '1236')]
I don't want to iterate over the list, to get the ip address values. Is there any way I can get a setof ip address directly , something like.
ip_addr = ['192.168.1.1','192.168.1.3']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用这样的集合理解:
...它将给...
You can use a set comprehension like this:
...which will give...
使用词典提取和重复IPS:
Using a dictionary to extract and deduplicate the IPs: