I have a list of strings
['apple_orange_percentage_0.709_0.752',
'apple_orange_percentage_0.752_0.786',
'apple_orange_percentage_0.673_0.709']
I need just a list of the unique numbers here:
[0.673, 0.709, 0.752, 0.786]
Could someone guide me on how to get there?
>Solution :
If you’re not concerned about the order of the values in your output list then:
data = ['apple_orange_percentage_0.709_0.752',
'apple_orange_percentage_0.752_0.786',
'apple_orange_percentage_0.673_0.709']
s = set()
for sv in data:
s.update(map(float, sv.split('_')[-2:]))
print(list(s))
output:
[0.673, 0.752, 0.709, 0.786]