you can sort listsource based on listkey
For example:
you have listsource = ['c','b','a']
and listkey = [2,3,1] # this will be used to sort listsource.
def sortbasedlist(sources,keys):
#combine (key,sources)
Kombin = [(keys[i],sources[i]) for i in range(len(sources))]
Kombin.sort()
return [source for (key,source) in Kombin]
main program:
print sortbasedlist(listsource,listkey) # this will result ('a','c','b')
And for your problem you can do something like this:
# suppose files already found and can be considered as source
filesKey = [x[-2:] for x in files]
Result = sortbasedlist(files,filesKey)
good luck.
pujo
On 5/24/05, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Jonas Melian wrote:
> > Kent Johnson wrote:
> >>files = glob.glob(os.path.join(dir_locales, "*_[A-Z][A-Z]"))
> >>files.sort(key=lastTwoChars) # Note: NOT key=lastTwoChars()
> >
> > I get:
> > ::
> > files.sort(key=lastTwoChars)
> > TypeError: sort() takes no keyword arguments
> > ::
> >
> > Could it be by the Python version? I have Python 2.3.5
>
> Yes, the key= parameter is new in Python 2.4. For Python 2.3 you can define a
> comparison function, e.g.
>
> def cmpLastTwoChars(a, b):
> return cmp(a[-2:], b[-2:])
>
> files.sort(cmpLastTwoChars)
>
> Kent
>
> _______________________________________________
> Tutor maillist - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor