sorting mixed lists
hi guys n girls
im making a list of the biggest files on my computer i have got most of the coding done but i have hit a brick wall with the sort function.
i can sort the size or the file name but as they are both in the same list i cannot sort by size as they have got rid of this function in python 3.1 if anyone can help me with this it would be great!
\/ example of list \/
size F.name
[256, '.\\abc.py']
[366, '.\\test123.py']
[286, '.\\testab.py']
[0, '.\\dir1\\Copy (10) of New Text Document (2).txt']
[0, '.\\dir1\\Copy (10) of New Text Document.txt']
[82, '.\\dir1\\Copy (10) of tessdfsdt5.txt']
\/ code to get the list \/
import os
folder = ('.')
fsize=list()
filename=list()
filesize=list()
for (path, dirs, files) in os.walk(folder):
for dirs in path:
for file in files:
filename = os.path.join(path, file)
file_size = os.path.getsize(filename)
fsize= file_size, filename
Fsize=list(fsize)
#Fsize.sort()--->>> TypeError: unorderable types: str() < int()
print(Fsize)
break
danholding
Junior Poster in Training
56 posts since Aug 2010
Reputation Points: 15
Solved Threads: 1
hey sorry im still a newbie to python lang.
i have created the list containing the file and date but cannot sort it
and yes i do want to sort them by the size. i have done this in 2.5 but as i have seen from forums you cannot sort a list of two different elements.
do you know why they got rid of this feature as i have used it for quite a few little tasks in 2.5 and always worked perfectly.
sorry if this is confusing, I've confused myself at some points.
danholding
Junior Poster in Training
56 posts since Aug 2010
Reputation Points: 15
Solved Threads: 1
hey i have just tried it and it doesn't seem to want to create the database.
if possible i want to just sort the files via the size this is the code i have so far which works but does not sort properly \/
import os
folder = ('.')
#size, count = '', 0
filename=list()
file_size=list()
for (path, dirs, files) in os.walk(folder):
for dirs in path:
for file in files:
#size, count = '', 0
filename = os.path.join(path, file)
file_size = str(os.path.getsize(filename))
#if len(file_size) > 12:
#'%2d' % filesize
#count += 1
fsize=list()
fsize.append(file_size + filename)
#fsize.append(filename)
#print(fsize)
fsize.sort()# i do not receive errors but it does not sort them or if it does i can see what it is sorting it by
print(fsize)
break
danholding
Junior Poster in Training
56 posts since Aug 2010
Reputation Points: 15
Solved Threads: 1