我有这个列表,有5个数字序列:
['123', '134', '234', '214', '223']
我想获得每个数字序列的第i个位置中每个数字1,2,3,4的百分比.例如,这5个数字序列的第0位的数字是1 1 2 2 2,那么我需要计算百分比
在这个数字序列中,1,2,3,4返回百分比作为新列表的第0个元素.
['123', '134', '234', '214', '223']
0th position: 1 1 2 2 2 the percentage of 1,2,3,4 are respectively: [0.4, 0.6, 0.0, 0.0]
1th position: 2 3 3 1 2 the percentage of 1,2,3,4 are respectively: [0.2, 0.4, 0.4, 0.0]
2th position: 3 4 4 4 3 the percentage of 1,2,3,4 are respectively: [0.0, 0.0, 0.4, 0.6]]
然后期望的结果是返回:
[[0.4, 0.6, 0.0, 0.0], [0.2, 0.4, 0.4, 0.0], [0.0, 0.0, 0.4, 0.6]]
我到目前为止的尝试:
list(zip(*['123', '134', '234', '214', '223']))
结果:
[('1', '1', '2', '2', '2'), ('2', '3', '3', '1', '2'), ('3', '4', '4', '4', '3')]
但我被困在这里,然后我不知道如何计算每个数字1,2,3,4的元素的百分比,然后获得所需的结果.任何建议表示赞赏!