How to do an ascending order of a folder’s items stored in a list with python?

I have a folder that contains some xml files. I’m trying to read those files and store it in a list in ascending order. I have written the following codes, nonetheless, I’m not sure how to do it. The folder contains files such as:

a.xml_1

a.xml_2

a.xml_3

When I run the following codes, the created list is not ordered.

import os

path = 'mypath/folder/'

xml_files=[]
files = os.listdir(path)

for f in files:
    xml_files=[f]
    print(xml_files)

Answer

Try this one, it will give you all the files sorted in ascending order in a single list

import os

path = 'mypath/folder/'

xml_files=[]
files = os.listdir(path)

for f in files:
    xml_files.append(f)
xml_files.sort()
print(xml_files)