OK - I actually got something working last night with a list that is then
converted into a dictionary (dealing with small sets of data - < 200 files per
run). However, I like the sorted list option - I didn't realize that was even
an option within the definition and wasn't quite sure how to get th
Maybe simpler but not very much simpler: one line for each solution.
And in your solution the lambda is evaluated at each comparaison of the sort algorithm isn't it?
So your code seems less productive than the bengt's code which apply
the same code as the lambda only one time by entry in the li
On Fri, 12 Aug 2005, Bengt Richter wrote:
> On Fri, 12 Aug 2005 00:06:17 GMT, Peter A. Schott <[EMAIL PROTECTED]> wrote:
>
>> Trying to operate on a list of files similar to this:
>>
>> test.1
>> test.2
>> test.3
>>
>> I want to sort them in numeric order instead of string order.
>
> >>> [name for
Bengt Richter wrote:
[name for dec,name in sorted((int(nm.split('.')[1]),nm) for nm in namelist)]
>
> ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20']
Giving a key argument to sorted will make it simpler::
>>> sorted(namelist, key=lambda x:int(x.rsplit('.')[-1]))
--
On Fri, 12 Aug 2005 00:06:17 GMT, Peter A. Schott <[EMAIL PROTECTED]> wrote:
>Trying to operate on a list of files similar to this:
>
>test.1
>test.2
>test.3
>test.4
>test.10
>test.15
>test.20
>
>etc.
>
>I want to sort them in numeric order instead of string order. I'm starting
>with
>this code:
Trying to operate on a list of files similar to this:
test.1
test.2
test.3
test.4
test.10
test.15
test.20
etc.
I want to sort them in numeric order instead of string order. I'm starting with
this code:
import os
for filename in [filename for filename in os.listdir(os.getcwd())]:
print