我想在python 3.x中将['123', '213', 'acd', '321', 'dac']
更改为[['123', '321', '213'], ['acd', 'dac']]
。
答案 0 :(得分:1)
我认为这是达到所需目标的最简单方法:
arr = ['123', '213', 'acd', '321', 'dac']
new_arr = [[], []]
for element in arr:
try:
new_arr[0].append(int(element))
except ValueError:
new_arr[1].append(element)
print(new_arr)