1

So I've got some files that look like this .../100keV8cm.txt. This goes from 1-10 cm and 80,100,120 keV. The problem is that when I try to sort them, it places 1-9cm in the correct order for all energies but it places the 10cm one for each energy at the end of the appended list. This is the code I have so far:

for i in range(emin,emax+steps,steps):
    for filename in os.listdir(directory):
        if f'{i}keV' in filename:
            input_files.append(directory + filename)
        else:
            continue
    emin+=steps
    input_files.sort(key=lambda f: int(''.join(filter(str.isdigit, f))))

I want it to go 1-10cm for 80keV, then the next 10 files for 100keV and so on.

Nikaido
  • 4,443
  • 5
  • 30
  • 47
D.Cecchi
  • 25
  • 3
  • Sorry, correction. The last line should not be indented. It should be out of the for loops. – D.Cecchi Oct 22 '19 at 14:30
  • You can [edit] the question to fix that. Also note @Nikaido has suggested an edit to fix the formatting, which I suggest you approve first. – wjandrea Oct 22 '19 at 14:32
  • Just write the `lambda` to return tuple of the values instead of single value. Look at https://stackoverflow.com/a/4233482/9327628 – Marek Schwarz Oct 22 '19 at 14:44

0 Answers0