Bubble Sort Implementation in Python 3
Unnecessary Function

Your swap function is unnecessary. Simply replace the function call with this line:

nums[j], nums[j + 1] = nums[j + 1], nums[j]


This does the swapping for you.

Spacing

There should be spaces between values in lists

[1, 2, 3, 4, 5]


between numbers/strings and operators

if nums[j] &gt; nums[j + 1]


and between parameters in a function call

for j in range(0, len(nums) - 1 - i, 1):


Type Hints

Your function header can look like this:

from typing import List, Union

def bubble_sort(nums: List[Union[int, float]]) -&gt; List[Union[int, float]]:


What this says is that the function accepts a list of integers/floats, and returns a list of integers/floats. It adds another layer of descriptiveness to your code.

Docstrings

You should include a docstring at the beginning of every class/method/module you write. This allows you to describe in words what your code is doing.

def bubble_sort(nums: List[Union[int, float]]) -&gt; List[Union[int, float]]:
    """
    A bubble sort algorithm, etc etc etc

    :param nums -&gt; List: A list of integers/floats to sort

    :return List: The sorted list of integers/floats, from smallest -&gt; biggest
    """