Ways to Sort List of Float Values - Python Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a list of float values, our task is to sort them in ascending order. For example, given [3.1, 2.4, 5.6, 1.8], the sorted output should be: [1.8, 2.4, 3.1, 5.6]Using sorted()Python’s built-in sorted() function sorts the list in ascending order by default. It is efficient and works well for most cases. Python a = [3.1, 2.4, 5.6, 1.8] s = sorted(a) print(s) Output[1.8, 2.4, 3.1, 5.6] Explanation:sorted(a) returns a new sorted list without modifying the original.It uses Timsort which has an average time complexity of O(n log n).Using .sort() .sort() method sorts the list in place modifying the original list instead of returning a new one. Python a = [3.1, 2.4, 5.6, 1.8] a.sort() print(a) Output[1.8, 2.4, 3.1, 5.6] Explanation:.sort() modifies a instead of creating a new list.It also uses Timsort, with an average time complexity of O(n log n) and this is useful when memory efficiency is a priority.Using Bubble Sort We can manually sort the list using the Bubble Sort algorithm which repeatedly swaps adjacent elements if they are in the wrong order. Python a = [3.1, 2.4, 5.6, 1.8] n = len(a) for i in range(n): for j in range(n - i - 1): if a[j] > a[j + 1]: a[j], a[j + 1] = a[j + 1], a[j] # Swap elements print(a) Output[1.8, 2.4, 3.1, 5.6] Explanation:We loop through the list multiple times, pushing the largest number to the right on each pass.if a[j] > a[j + 1] condition checks if two adjacent numbers are out of order.The a[j], a[j + 1] = a[j + 1], a[j] swap corrects their order. Comment More infoAdvertise with us Next Article Sort Tuple of Lists in Python E everythingispossible Follow Improve Article Tags : Python Python Programs Python list-programs Python-sort Practice Tags : python Similar Reads Python | Ways to sort a zipped list by values Sorting a zipped list in Python refers to arranging pairs of elements, typically tuples, based on their values. This allows us to reorder the list according to the second item in each pair, while keeping the key-value relationship intact. In this article we'll explore ways to sort a zipped list by v 2 min read Fastest Way to Sort in Python Sorting is a fundamental operation in Python. Whether we are working with numbers, strings or complex data structures knowing how to sort efficiently is key to optimizing performance. In this article, we will explore the fastest way to sort in Python breaking down the built-in sorting techniques and 3 min read Sort Tuple of Lists in Python The task of sorting a tuple of lists involves iterating through each list inside the tuple and sorting its elements. Since tuples are immutable, we cannot modify them directly, so we must create a new tuple containing the sorted lists. For example, given a tuple of lists a = ([2, 1, 5], [1, 5, 7], [ 3 min read Convert Float String List to Float Values-Python The task of converting a list of float strings to float values in Python involves changing the elements of the list, which are originally represented as strings, into their corresponding float data type. For example, given a list a = ['87.6', '454.6', '9.34', '23', '12.3'], the goal is to convert ea 3 min read Python - Sort List by Dictionary values Sometimes while working with a Python dictionary, we can have problems in which we need to perform a sort of list according to the corresponding value in the dictionary. This can have applications in many domains, including data and web development. Let's discuss certain ways in which this task can 3 min read Sort a List of Python Dictionaries by a Value Sorting a list of dictionaries by a specific value is a common task in Python programming. Whether you're dealing with data manipulation, analysis, or simply organizing information, having the ability to sort dictionaries based on a particular key is essential. In this article, we will explore diffe 3 min read Like