Hey All!
Here is the answer to your question @sndhu.rani
To sort each set, you can use Python’s sorted()
function. For any iterable, including a set, sorted(s)
will return a list of elements sorted in ascending order. Here’s an example:
s = set(['0.000000000', '0.009518000', '10.277200999', '0.030810999', '0.018384000', '4.918560000'])
print(sorted(s))
Output:
['0.000000000', '0.009518000', '0.018384000', '0.030810999', '10.277200999', '4.918560000']
Just remember, sorted()
returns a list, not a set, because sets don’t have any inherent order. If you want to sort these as numbers rather than strings, you’ll need to convert them to float
during sorting. You can do that with the key
parameter:
print(sorted(s, key=float))
Output:
['0.000000000', '0.009518000', '0.018384000', '0.030810999', '4.918560000', '10.277200999']
This method works great if you’re dealing with strings that represent numbers. But ideally, you should store the numbers as actual numeric values if possible.