Q:

Cannot convert from str to int in list (python)

def prepare_for_sort(st):
 nums = str(st).split()
 for each in nums:
    each = int(each)
 print(nums)

st  is string with number like "20 50 4 8 4 64 6 47 8". Nums must be array of integer. Why this doesnt work?

A:

This doesn't work because your variable each is a reference to some object: first, to the same object that's also contained in the list, then, to an integer object. each is, however, in no way connected to the list the content of which you want to manipulate.
You could manipulate the list in-place:
for index, value in enumerate(nums):
    nums[index] = int(value)

Or you can create a new list instead:
nums = [int(value) for value in nums]

