如何将一组数字字符串转换为一组整数?

mic*_*ael -2 python string int set

我有一套

set1= { '1', '2' }
Run Code Online (Sandbox Code Playgroud)

我想将'1','2'转换为int,就像这样:

set_new = { 1, 2 }
Run Code Online (Sandbox Code Playgroud)

如何在python中做到这一点?

Viv*_*ble 6

使用地图功能

演示:

>>> set1= { '1', '2' }
>>> set2 = set(map(int, set1))
>>> set2
set([1, 2])
Run Code Online (Sandbox Code Playgroud)