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),
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
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
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
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
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:/
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
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
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
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
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
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
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
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
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
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
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
>
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
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
> 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
เมื่อ วันจันทร์ที่ 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
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.
เมื่อ วันจันทร์ที่ 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
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
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.
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.
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.
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
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
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,
>
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
>
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.
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
>> 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_
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
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),
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
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,
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
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
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
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
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():
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
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
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
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
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)==
>>> 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
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
>
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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,
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
': 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
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
': 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
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
;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
''),
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
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
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
A comprehensive and educational answer, Peter. Thank you.
Josh
--
https://mail.python.org/mailman/listinfo/python-list
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:
>>>
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
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__
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
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
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
>
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://
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/
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
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
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
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
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
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
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
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
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
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
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
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
"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
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
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 - 100 of 324 matches
Mail list logo