Re: Best way to insert sorted in a list

2017-09-08 Thread Stephan Houben
Timsort ( https://en.wikipedia.org/wiki/Timsort ) algorithm. Timsort is O(N) in the special case of a list of N elements where the first N-1 are already sorted and the last one is arbitrary. So appending the value and then calling sort() is in fact O(N) in Python (hence asymptotically optimal),

Re: Best way to insert sorted in a list

2017-09-08 Thread Steve D'Aprano
y to say about this ? What is the best (fastest) >> way to insert sorted in a list ? > > a = [] > num = int(input('How many numbers: ')) > for n in range(num): > numbers = int(input('Enter values:')) > a.append(numbers) > > b = sorted(a) &g

Re: Best way to insert sorted in a list

2017-09-08 Thread logonveera
ht. > > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? a = [] num = int(input('How many numbers: ')) for n in range(num): numbers = int(input('Enter values:')) a.append(numbers) b = sorted(a) p

Re: Merging multiple sorted sequences.

2017-04-17 Thread Andre Müller
Hi, when you have lists with different lengths and want to zip them, you should look at itertools.zip_longest Greetings Andre -- https://mail.python.org/mailman/listinfo/python-list

Re: Merging multiple sorted sequences.

2017-04-13 Thread Erik
On 13/04/17 07:30, Peter Otten wrote: Verdict: not greedy ;) Great (as I mentioned I did look at the code VERY quickly whilst VERY tired and at first glance missed that it's doing almost exactly what my code is doing except using the heapq to manage tracking the smallest value rather than so

Re: Merging multiple sorted sequences.

2017-04-12 Thread Peter Otten
Erik wrote: > Hi Peter, > > On 12/04/17 23:42, Peter Otten wrote: >> Erik wrote: >> >>> I need to be able to lazily merge a variable number of already-sorted(*) >>> variable-length sequences into a single sorted sequence. >> >> https:/

Re: Merging multiple sorted sequences.

2017-04-12 Thread Paul Rubin
Erik writes: > I need to be able to lazily merge a variable number of > already-sorted(*) variable-length sequences If the number of sequences is large, the traditional way is with the heapq module. -- https://mail.python.org/mailman/listinfo/python-list

Re: Merging multiple sorted sequences.

2017-04-12 Thread Cameron Simpson
On 12Apr2017 23:15, Erik wrote: I need to be able to lazily merge a variable number of already-sorted(*) variable-length sequences into a single sorted sequence. The merge should continue until the longest sequence has been exhausted. (*) They may in practice be a lazy source of data known

Re: Merging multiple sorted sequences.

2017-04-12 Thread Terry Reedy
On 4/12/2017 7:15 PM, Erik wrote: Hi Peter, On 12/04/17 23:42, Peter Otten wrote: Erik wrote: I need to be able to lazily merge a variable number of already-sorted(*) variable-length sequences into a single sorted sequence. https://docs.python.org/dev/library/heapq.html#heapq.merge

Re: Merging multiple sorted sequences.

2017-04-12 Thread Erik
Hi Ian, On 13/04/17 00:09, Erik wrote: On 12/04/17 23:44, Ian Kelly wrote: I would just use "lowest = min(items, key=itemgetter(0))". I had it in my head for some reason that min() would return the smallest key, not the object (and hence I wouldn't be able to know which sequence object to get

Re: Merging multiple sorted sequences.

2017-04-12 Thread Erik
Hi Peter, On 12/04/17 23:42, Peter Otten wrote: Erik wrote: I need to be able to lazily merge a variable number of already-sorted(*) variable-length sequences into a single sorted sequence. https://docs.python.org/dev/library/heapq.html#heapq.merge AFAICT (looking at the Python 3.5 heapq

Re: Merging multiple sorted sequences.

2017-04-12 Thread Erik
On 12/04/17 23:44, Ian Kelly wrote: This might be okay since Timsort on an already-sorted list should be O(n). But there's not really any need to keep them sorted and I would just use "lowest = min(items, key=itemgetter(0))". Sure (and this was my main worry). I had it in m

Re: Merging multiple sorted sequences.

2017-04-12 Thread Ian Kelly
On Wed, Apr 12, 2017 at 4:44 PM, Ian Kelly wrote: > On Wed, Apr 12, 2017 at 4:15 PM, Erik wrote: >> while len(items) > 1: >> items.sort(key=lambda item: item[0]) > > This might be okay since Timsort on an already-sorted list should be > O(n). But there&#x

Re: Merging multiple sorted sequences.

2017-04-12 Thread Ian Kelly
On Wed, Apr 12, 2017 at 4:15 PM, Erik wrote: > Hi. > > I need to be able to lazily merge a variable number of already-sorted(*) > variable-length sequences into a single sorted sequence. The merge should > continue until the longest sequence has been exhausted. > > (*) They

Re: Merging multiple sorted sequences.

2017-04-12 Thread Peter Otten
Erik wrote: > I need to be able to lazily merge a variable number of already-sorted(*) > variable-length sequences into a single sorted sequence. https://docs.python.org/dev/library/heapq.html#heapq.merge -- https://mail.python.org/mailman/listinfo/python-list

Merging multiple sorted sequences.

2017-04-12 Thread Erik
Hi. I need to be able to lazily merge a variable number of already-sorted(*) variable-length sequences into a single sorted sequence. The merge should continue until the longest sequence has been exhausted. (*) They may in practice be a lazy source of data known to only ever be generated in

Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread breamoreboy
On Monday, October 10, 2016 at 5:25:46 PM UTC+1, Nuen9 wrote: > > Hi! > > > > Could it be, "Nuen9", that you would like to find a split where the > > split sums are close to each other? In other words, you define the > > number of splits (in your example: 3) and the algortihm should test all >

Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread K. Elo
Hi! Here one possible solution: --- snip --- land = [10,20,30,40,110,50,18,32,5] landlength=len(land) winnersplit=[] for i in range(landlength-2): for j in range(landlength-1-i): splitsums=[sum(land[0:(i+1)]), sum(land[(i+1):(i+j+2)]), sum(land[(i+j+2):landlength])] differences

Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Emile van Sebille
On 10/10/2016 09:25 AM, Nuen9 wrote: Hi! Could it be, "Nuen9", that you would like to find a split where the split sums are close to each other? In other words, you define the number of splits (in your example: 3) and the algortihm should test all possible combinations and select the split where

Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Nuen9
> Hi! > > Could it be, "Nuen9", that you would like to find a split where the > split sums are close to each other? In other words, you define the > number of splits (in your example: 3) and the algortihm should test all > possible combinations and select the split where the sum differences are

Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Nuen9
เมื่อ วันจันทร์ที่ 10 ตุลาคม ค.ศ. 2016 22 นาฬิกา 46 นาที 33 วินาที UTC+7, K. Elo เขียนว่า: > Hi! > > Could it be, "Nuen9", that you would like to find a split where the > split sums are close to each other? In other words, you define the > number of splits (in your example: 3) and the algortihm

Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread K. Elo
Hi! Could it be, "Nuen9", that you would like to find a split where the split sums are close to each other? In other words, you define the number of splits (in your example: 3) and the algortihm should test all possible combinations and select the split where the sum differences are smallest.

Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Nuen9
เมื่อ วันจันทร์ที่ 10 ตุลาคม ค.ศ. 2016 21 นาฬิกา 31 นาที 25 วินาที UTC+7, Steve D'Aprano เขียนว่า: > On Tue, 11 Oct 2016 12:38 am, amornsak@gmail.com wrote: > > > I have a list is > > > > land = [10,20,30,40,110,50,18,32,5] > > > > and I want to fi

Re: Deviding N(1, 2, 3, .., N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Steve D'Aprano
On Tue, 11 Oct 2016 12:38 am, amornsak@gmail.com wrote: > I have a list is > > land = [10,20,30,40,110,50,18,32,5] > > and I want to find each values of summation (don't sorted values in list) > as It has highest as possible > > example. > > I want to d

Re: Deviding N(1, 2, 3, .., N) part from numeric list as summation of each values(don't sorted) has highest possible.

2016-10-10 Thread Ben Bacarisse
Nune9 writes: > I have a list is > > land = [10,20,30,40,110,50,18,32,5] > > and I want to find each values of summation (don't sorted values in > list) as It has highest possible > > example. > > I want to dividing N=3 part from list as above and divieded eac

Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Nuen9
Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible. The first I'm sorry for my English language. I have a list is land = [10,20,30,40,110,50,18,32,5] and I want to find each values of summation (don't sorted values

Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread amornsak . nak
Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible. The first I'm sorry for my English language. I have a list is land = [10,20,30,40,110,50,18,32,5] and I want to find each values of summation (don't sorted values

Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest possible.

2016-10-10 Thread Nune9
Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest possible. The first I'm sorry for my English language. I have a list is land = [10,20,30,40,110,50,18,32,5] and I want to find each values of summation (don't sorted values in l

Re: How to get a directory list sorted by date?

2016-05-16 Thread Random832
On Sun, May 15, 2016, at 17:52, Chris Angelico wrote: > On Mon, May 16, 2016 at 2:00 AM, Grant Edwards > wrote: > > On 2016-05-15, Michael Selik wrote: > >> On Sun, May 15, 2016, 10:37 AM Grant Edwards > >> wrote: > >>> On 2016-05-15, Tim Chase wrot

Re: How to get a directory list sorted by date?

2016-05-15 Thread Chris Angelico
On Mon, May 16, 2016 at 2:00 AM, Grant Edwards wrote: > On 2016-05-15, Michael Selik wrote: >> On Sun, May 15, 2016, 10:37 AM Grant Edwards >> wrote: >>> On 2016-05-15, Tim Chase wrote: >>>> >>>> unless sorted() returns a lazy sorter, >

Re: How to get a directory list sorted by date?

2016-05-15 Thread cl
Tim Chase wrote: > On 2016-05-15 14:36, Grant Edwards wrote: > > On 2016-05-15, Tim Chase wrote: > > > unless sorted() returns a lazy sorter, > > > > What's a lazy sorter? > > A hypothetical algorithm that can spool out a sorted sequence without >

Re: How to get a directory list sorted by date?

2016-05-15 Thread Tim Chase
On 2016-05-15 14:36, Grant Edwards wrote: > On 2016-05-15, Tim Chase wrote: > > unless sorted() returns a lazy sorter, > > What's a lazy sorter? A hypothetical algorithm that can spool out a sorted sequence without holding the entire sequence in memory at the same time.

Re: How to get a directory list sorted by date?

2016-05-15 Thread Grant Edwards
On 2016-05-15, Michael Selik wrote: > On Sun, May 15, 2016, 10:37 AM Grant Edwards > wrote: >> On 2016-05-15, Tim Chase wrote: >>> >>> unless sorted() returns a lazy sorter, >> >> What's a lazy sorter? > > One that doesn't calculate

Re: How to get a directory list sorted by date?

2016-05-15 Thread Michael Selik
>> return os.path.getmtime(path) > >> > >> return sorted(os.listdir(folder), key=getmtime, reverse=True) > >> > >> The same idea will work with pathlib and os.scandir(): > >> > >> def _getmtime(entry): > >> return entry.stat().st_

Re: How to get a directory list sorted by date?

2016-05-15 Thread Joel Goldstick
urn os.path.getmtime(path) >>> >>> return sorted(os.listdir(folder), key=getmtime, reverse=True) >>> >>> The same idea will work with pathlib and os.scandir(): >>> >>> def _getmtime(entry): >>> return entry.stat().st_mt

Re: How to get a directory list sorted by date?

2016-05-15 Thread Grant Edwards
On 2016-05-15, Tim Chase wrote: > On 2016-05-15 11:46, Peter Otten wrote: >> def sorted_dir(folder): >> def getmtime(name): >> path = os.path.join(folder, name) >> return os.path.getmtime(path) >> >> return sorted(os.listdir(folder),

Re: How to get a directory list sorted by date?

2016-05-15 Thread Vincent Vande Vyvre
Le 15/05/2016 10:47, c...@isbd.net a écrit : I have a little Python program I wrote myself which copies images from a camera (well, any mounted directory) to my picture archive. The picture archive is simply a directory hierarchy of dates with years at the top, then months, then days. My Python

Re: How to get a directory list sorted by date?

2016-05-15 Thread Peter Otten
Tim Chase wrote: > On 2016-05-15 11:46, Peter Otten wrote: >> def sorted_dir(folder): >> def getmtime(name): >> path = os.path.join(folder, name) >> return os.path.getmtime(path) >> >> return sorted(os.listdir(folder), key=getmtime,

Re: How to get a directory list sorted by date?

2016-05-15 Thread Chris Angelico
On Sun, May 15, 2016 at 9:15 PM, Tim Chase wrote: > On 2016-05-15 11:46, Peter Otten wrote: >> def sorted_dir(folder): >> def getmtime(name): >> path = os.path.join(folder, name) >> return os.path.getmtime(path) >> >> return sorted(os

Re: How to get a directory list sorted by date?

2016-05-15 Thread Tim Chase
On 2016-05-15 11:46, Peter Otten wrote: > def sorted_dir(folder): > def getmtime(name): > path = os.path.join(folder, name) > return os.path.getmtime(path) > > return sorted(os.listdir(folder), key=getmtime, reverse=True) > > The same idea wi

Re: How to get a directory list sorted by date?

2016-05-15 Thread Tim Chase
On 2016-05-15 20:48, Steven D'Aprano wrote: > Also, remember that most operating systems provide (at least) three > different times. I'm not sure which one you want, but if I had to > guess, I would probably guess mtime. If I remember correctly: > > atime is usually the last access time; > mtime i

Re: How to get a directory list sorted by date?

2016-05-15 Thread Steven D'Aprano
fname)).st_mtime location = '/tmp/' files = sorted(os.listdir(location), key=functools.partial(by_date, location)) The mysterious call to functools.partial creates a new function which is exactly the same as by_date except the "where" argument is already filled in. If functools.pa

Re: How to get a directory list sorted by date?

2016-05-15 Thread Peter Otten
find the time with os.path.getmtime(), then sort: def sorted_dir(folder): def getmtime(name): path = os.path.join(folder, name) return os.path.getmtime(path) return sorted(os.listdir(folder), key=getmtime, reverse=True) The same idea will work with pathlib and os.scandir():

How to get a directory list sorted by date?

2016-05-15 Thread cl
I have a little Python program I wrote myself which copies images from a camera (well, any mounted directory) to my picture archive. The picture archive is simply a directory hierarchy of dates with years at the top, then months, then days. My Python program simply extracts the date from the imag

Re: Please help on this sorted function

2015-06-03 Thread Steven D'Aprano
On Wednesday 03 June 2015 06:42, Joonas Liik wrote: > my_dict = {1: 'D', 2: 'B', 3: 'A', 4: 'E', 5: 'B'} > > # dict.items() returns an iterator that returns pairs of (key, value) > # pairs the key argument to sorted tells sorte

Re: Please help on this sorted function

2015-06-03 Thread Gary Herron
On 06/02/2015 01:20 PM, fl wrote: Hi, I try to learn sorted(). With the tutorial example: ff=sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) ff [1, 2, 3, 4, 5] I don't see what sorted does in this dictionary, i.e. the sequence of

Re: Please help on this sorted function

2015-06-02 Thread Chris Angelico
On Wed, Jun 3, 2015 at 6:25 AM, fl wrote: > I am still new to Python. How to get the sorted dictionary output: > > {1: 'D', 2: 'B', 3: 'A', 4: 'E', 5: 'B'} Since dictionaries don't actually have any sort of order to them, the best t

Re: Please help on this sorted function

2015-06-02 Thread Joonas Liik
my_dict = {1: 'D', 2: 'B', 3: 'A', 4: 'E', 5: 'B'} # dict.items() returns an iterator that returns pairs of (key, value) pairs # the key argument to sorted tells sorted what to sort by, operator.itemgetter is a factory function , itemgetter(1)==

Re: Please help on this sorted function

2015-06-02 Thread Joonas Liik
>>> ff=sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) >>> ff [1, 2, 3, 4, 5] sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) is equivalent to sorted(iter({1: 'D', 2

Re: Please help on this sorted function

2015-06-02 Thread fl
On Tuesday, June 2, 2015 at 1:20:40 PM UTC-7, fl wrote: > Hi, > > I try to learn sorted(). With the tutorial example: > > > > > >>> ff=sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) > >>> ff >

Please help on this sorted function

2015-06-02 Thread fl
Hi, I try to learn sorted(). With the tutorial example: >>> ff=sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) >>> ff [1, 2, 3, 4, 5] I don't see what sorted does in this dictionary, i.e. the sequence of 1..5 is unc

Re: How to show a dictionary sorted on a value within its data?

2014-10-03 Thread Chris Angelico
On Fri, Oct 3, 2014 at 5:55 PM, Steven D'Aprano wrote: >> which return non-list iterables. There's no really convenient equivalent >> to the map() usage of "call this function with each of these args, and >> discard the return values", as it looks very odd to do a list comp for >> nothing: > > map

Re: How to show a dictionary sorted on a value within its data?

2014-10-03 Thread Steven D'Aprano
On Fri, 03 Oct 2014 12:44:32 +1000, Chris Angelico wrote: > On Fri, Oct 3, 2014 at 9:16 AM, Steven D'Aprano > wrote: >>> Anyway, pylint doesn't complain about a bare use of lambda, but it >>> does complain about a map applied to a lambda or a filter applied to a >>> lambda. Pylint says they coul

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Chris Angelico
On Fri, Oct 3, 2014 at 9:16 AM, Steven D'Aprano wrote: >> Anyway, pylint doesn't complain about a bare use of lambda, but it >> does complain about a map applied to a lambda or a filter applied to a >> lambda. Pylint says they could be replaced by a list comprehension, >> with the warning "deprec

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Steven D'Aprano
Dan Stromberg wrote: > On Thu, Oct 2, 2014 at 12:15 PM, Ian Kelly wrote: >> On Thu, Oct 2, 2014 at 10:33 AM, wrote: >>> Ah, so at least there is a reason for it, I'm far from being a >>> mathematician though so it's not particularly obvious (for me anyway). >> >> You're not alone; a lot of peop

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Chris Angelico
On Fri, Oct 3, 2014 at 6:06 AM, Dan Stromberg wrote: > Anyway, pylint doesn't complain about a bare use of lambda, but it > does complain about a map applied to a lambda or a filter applied to a > lambda. Pylint says they could be replaced by a list comprehension, > with the warning "deprecated-l

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Dan Stromberg
On Thu, Oct 2, 2014 at 12:15 PM, Ian Kelly wrote: > On Thu, Oct 2, 2014 at 10:33 AM, wrote: >> Ah, so at least there is a reason for it, I'm far from being a >> mathematician though so it's not particularly obvious (for me anyway). > > You're not alone; a lot of people find the terminology not i

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Grant Edwards
On 2014-10-02, c...@isbd.net wrote: > Grant Edwards wrote: >> On 2014-10-02, c...@isbd.net wrote: >> >> > It throws me because 'lambda' simply has no meaning whatsoever for me, >> > i.e. it's just a greek letter. >> > >> > So from my point of view it's like seeing 'epsilon' stuck in the >> > mid

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Ian Kelly
On Thu, Oct 2, 2014 at 10:33 AM, wrote: > Ah, so at least there is a reason for it, I'm far from being a > mathematician though so it's not particularly obvious (for me anyway). You're not alone; a lot of people find the terminology not intuitive. Even GvR has publicly lamented the choice of key

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Rustom Mody
On Thursday, October 2, 2014 4:47:50 PM UTC+5:30, Marko Rauhamaa wrote: > > It's not as if I'm new to programming either, I've been writing > > software professionally since the early 1970s, now retired. I have no > > formal computer training, there wasn't much in the way of university > > courses

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread cl
Grant Edwards wrote: > On 2014-10-02, c...@isbd.net wrote: > > Travis Griggs wrote: > >> > >> > >> Sent from my iPhone > >> > >> > On Oct 1, 2014, at 04:12, Peter Otten <__pete...@web.de> wrote: > >> > > >> > `lambda` is just a fancy way to define a function inline > >> > >> Not sure "fancy

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Grant Edwards
On 2014-10-02, c...@isbd.net wrote: > Travis Griggs wrote: >> >> >> Sent from my iPhone >> >> > On Oct 1, 2014, at 04:12, Peter Otten <__pete...@web.de> wrote: >> > >> > `lambda` is just a fancy way to define a function inline >> >> Not sure "fancy" is the correct adjective; more like syntac

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Marko Rauhamaa
c...@isbd.net: > It's not as if I'm new to programming either, I've been writing > software professionally since the early 1970s, now retired. I have no > formal computer training, there wasn't much in the way of university > courses on computing in the 1960s, I have a degree in Electrical > Engin

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread cl
Travis Griggs wrote: > > > Sent from my iPhone > > > On Oct 1, 2014, at 04:12, Peter Otten <__pete...@web.de> wrote: > > > > `lambda` is just a fancy way to define a function inline > > Not sure "fancy" is the correct adjective; more like syntactic tartness > (a less sweet version of syntact

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Travis Griggs
Sent from my iPhone > On Oct 1, 2014, at 04:12, Peter Otten <__pete...@web.de> wrote: > > `lambda` is just a fancy way to define a function inline Not sure "fancy" is the correct adjective; more like syntactic tartness (a less sweet version of syntactic sugar). :) -- https://mail.python.org

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
Joel Goldstick wrote: > On Wed, Oct 1, 2014 at 5:58 AM, wrote: > > I have a dictionary as follows:- > > > > { > > u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1', > > conv=6834.374834509803, > Description=u'Starter Amps'), > > u'LeisureVolts': Row(id=1, ain=u'AIN0', name=u'Leisur

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
x', conv=0.028125, Description=u''), > >> > u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', > >> > conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts': > >> > Row(id=2,

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Peter Otten
ain=u'AIN2', >> > name=u'LeisureAmps1', conv=32.727273081945, Description=u'Leisure >> > Amps'), u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', >> > conv=28.94469628911757, Description=u'Starter

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Joel Goldstick
': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', >> > conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts': >> > Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757, >> > Descript

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
32.727273081945, Description=u'Leisure Amps'), u'StarterVolts': > > Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757, > > Description=u'Starter Volts') } > > > > I want to output a menu to a user comprising some

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Joel Goldstick
': Row(id=2, ain=u'AIN1', name=u'StarterVolts', > conv=28.94469628911757, Description=u'Starter Volts') > } Is Row a function? Or do you have a key with a tuple as the value? > > I want to output a menu to a user comprising some parts of the > dictionary

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Mark Lawrence
ame=u'xx', conv=0.028125, Description=u''), u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts&#x

Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Peter Otten
;AIN6', name=u'xx', conv=0.028125, Description=u''), > u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', > conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts': > Row(id=2, ain=u'AIN1&#

How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
''), u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757, Description=u

Sorted Containers

2014-04-10 Thread Mark Lawrence
I've just chanced upon this and thought it might be of interest to some of you, haven't tried it myself http://www.grantjenks.com/docs/sortedcontainers/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is

Re: Oddity using sorted with key

2014-03-11 Thread Josh English
On Tuesday, March 11, 2014 9:25:29 AM UTC-7, John Gordon wrote: > > > > > Why do you say that 'key=lambda x: x.name.lower' is the correct form? That > > returns the str.lower() function object, which is a silly thing to sort > > on. Surely you want to sort on the *result* of that function, w

Re: Oddity using sorted with key

2014-03-11 Thread Josh English
A comprehensive and educational answer, Peter. Thank you. Josh -- https://mail.python.org/mailman/listinfo/python-list

Re: Oddity using sorted with key

2014-03-11 Thread Peter Otten
Josh English wrote: > I am running into a strange behavior using the sorted function in Python > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) Let's simplify your example some more: >>>

Re: Oddity using sorted with key

2014-03-11 Thread John Gordon
In <058a4a9e-7893-44ef-97c0-999a3589e...@googlegroups.com> Josh English writes: > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) > # END > The output is: > [Thing d, Thing f, Thing 2, Thin

Re: Oddity using sorted with key

2014-03-11 Thread emile
On 03/11/2014 09:13 AM, Josh English wrote: I am running into a strange behavior using the sorted function in Python 2.7. The key parameter is not behaving as the docs say it does: Here is a snippet of code, simplified from my full program: #begin code class Thing(object): def __init__

Re: Oddity using sorted with key

2014-03-11 Thread Chris Kaynor
On Tue, Mar 11, 2014 at 9:13 AM, Josh English wrote: > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > In this case, the key being sorted on is the function object x.name.lower, not the result of the call. It might make more sense if you break the lambda out into a separa

Oddity using sorted with key

2014-03-11 Thread Josh English
I am running into a strange behavior using the sorted function in Python 2.7. The key parameter is not behaving as the docs say it does: Here is a snippet of code, simplified from my full program: #begin code class Thing(object): def __init__(self, name): self.name = name def

Re: The default locale of sorted()

2012-12-03 Thread Ian Kelly
On Mon, Dec 3, 2012 at 3:17 PM, Peng Yu wrote: > Hi, > > I'm not able to find the documentation on what locale is used for > sorted() when the 'cmp' argument is not specified. Could anybody let > me what the default is? If I always want LC_ALL=C, do I need to >

The default locale of sorted()

2012-12-03 Thread Peng Yu
Hi, I'm not able to find the documentation on what locale is used for sorted() when the 'cmp' argument is not specified. Could anybody let me what the default is? If I always want LC_ALL=C, do I need to explicitly set the locale? Or it is the default? Regards, Peng -- http://

Re: Struggling with sorted dict of word lengths and count

2011-06-27 Thread Chris Angelico
On Tue, Jun 28, 2011 at 3:00 AM, Cathy James wrote: > for word in line.lower().split( ):#split lines into words and make lower > case By the way, side point: There's not much point lower-casing the line when all you care about is the lengths of words :) ChrisA -- http://mail.python.org/mailman/

Re: Struggling with sorted dict of word lengths and count

2011-06-27 Thread Chris Angelico
On Tue, Jun 28, 2011 at 3:00 AM, Cathy James wrote: > def fileProcess(filename = open('input_text.txt', 'r')): >     for line in filename: >     for word in line.lower().split( ):#split lines into words and make > lower case >     wordlen = word_length(word)#run function to return leng

Struggling with sorted dict of word lengths and count

2011-06-27 Thread Cathy James
Dear Python Programmers, I am a Python newby and I need help with my code: I have done parts of it but I can't get what I need: I need to manipulate text to come up with word lengths and their frequency:ie how many 1-letter words in a text how many 2-letter words in a text, etc I believe I am on

Re: Best way to insert sorted in a list

2011-06-19 Thread Vito De Tullio
SherjilOzair wrote: > There are basically two ways to go about this. [...] > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? a third way maybe using a SkipList instead of a list on http://infohost.nmt.edu/tcc/help/lang/python

Re: Best way to insert sorted in a list

2011-06-17 Thread Steven D'Aprano
On Fri, 17 Jun 2011 13:53:10 -0700, SherjilOzair wrote: > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? if you're doing repeated insertions into an already sorted list, there's no question that the bisect module is the

Re: Best way to insert sorted in a list

2011-06-17 Thread Chris Torek
gt;> This is O(log (n + m)), hence likely better than repeatedly inserting >> in the correct place. >Surely you mean O((n + m) log (n + m)). Er, "maybe"? (It depends on the relative values of m and n, and the underlying sort algorithm to some extent. Some algorithms are better

Re: Best way to insert sorted in a list

2011-06-17 Thread Ian Kelly
On Fri, Jun 17, 2011 at 3:48 PM, Chris Torek wrote: > If len(large_list) is m, this is O(m).  Inserting each item in > the "right place" would be O(m log (n + m)).  But we still > have to sort: > >    a.sort() > > This is O(log (n + m)), hence likely better than repeatedly inserting > in the corre

Re: Best way to insert sorted in a list

2011-06-17 Thread Ethan Furman
Chris Torek wrote: Appending to the list is much faster, and if you are going to dump a set of new items in, you can do that with: # wrong way: # for item in large_list: #a.append(item) # right way, but fundamentally still the same cost (constant # factor is much smaller

Re: Best way to insert sorted in a list

2011-06-17 Thread Chris Torek
s the community to say about this ? What is the best (fastest) >way to insert sorted in a list ? In this case, the "best" way is most likely "don't do that at all". First, we should note that a python list() data structure is actually an array. Thus, you can locate

Re: Best way to insert sorted in a list

2011-06-17 Thread Ian Kelly
On Fri, Jun 17, 2011 at 3:02 PM, Shashank Singh wrote: > Correct me if I am wrong here but isn't the second one is O(log N)? > Binary search? > That is when you have an already sorted list from somewhere and you > are inserting just one new value. Finding the position to insert

Re: Best way to insert sorted in a list

2011-06-17 Thread Ethan Furman
SherjilOzair wrote: What has the community to say about this ? What is the best (fastest) way to insert sorted in a list ? Check out the bisect module. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to insert sorted in a list

2011-06-17 Thread Shashank Singh
x27;s complexity is O(N), while the first one's is O(N * > log N). Correct me if I am wrong here but isn't the second one is O(log N)? Binary search? That is when you have an already sorted list from somewhere and you are inserting just one new value. In case you are building the whole li

Best way to insert sorted in a list

2011-06-17 Thread SherjilOzair
one works much better, because C code is being used instead of pythons. Still, being a programmer, using the first way (a.insert(x); a.sort()), does not feel right. What has the community to say about this ? What is the best (fastest) way to insert sorted in a list ? -- http://mail.python.o

Re: Sorted dictionary

2010-01-21 Thread Arnaud Delobelle
"Jan Kaliszewski" writes: > Dnia 21-01-2010 o 09:27:52 Raymond Hettinger napisał(a): > >> On Jan 20, 5:02 pm, "Jan Kaliszewski" wrote: > >>> http://code.activestate.com/recipes/576998/ > >> Using an underlying list to track sorted item

Re: Sorted dictionary

2010-01-21 Thread Daniel Stutzbach
On Thu, Jan 21, 2010 at 12:45 PM, Jan Kaliszewski wrote: > Please note that I used funcions from bisect, that use binary search. > > Doesn't it take O(log n) time? > It takes O(log n) time to find the point to insert, but O(n) time to perform the actual insertion. -- Daniel Stutzbach, Ph.D. Pre

Re: Sorted dictionary

2010-01-21 Thread Jan Kaliszewski
Dnia 21-01-2010 o 09:27:52 Raymond Hettinger napisał(a): On Jan 20, 5:02 pm, "Jan Kaliszewski" wrote: http://code.activestate.com/recipes/576998/ Using an underlying list to track sorted items means that insertion and deletion take O(n) time. That could be reduced to O(log

  1   2   3   4   >