【问题标题】:How can I convert a set of numeric strings to a set of integers?如何将一组数字字符串转换为一组整数?
【发布时间】:2015-05-24 11:41:24
【问题描述】:

我有一套

set1= { '1', '2' }

我想将 '1', '2' 转换为 int ,如下所示:

set_new = { 1, 2 }

如何在 python 中做到这一点?

【问题讨论】:

  • 你尝试过任何东西吗?
  • 尝试写一些代码。
  • 人们在认真地支持这个吗? facedesk

标签: python string int set


【解决方案1】:

使用map函数

演示:

>>> set1= { '1', '2' }
>>> set2 = set(map(int, set1))
>>> set2
set([1, 2])

【讨论】:

    猜你喜欢
    • 2021-06-14
    • 2012-02-26
    • 1970-01-01
    • 2016-08-03
    • 2019-04-21
    相关资源
    最近更新 更多