Re: Python usage numbers
On 13 fév, 04:09, Terry Reedy wrote: > > > * The new internal unicode scheme for 3.3 is pretty much a mixture of > the 3 storage formats (I am of course, skipping some details) by using > the widest one needed for each string. The advantage is avoiding > problems with each of the three. The disadvantage is greater internal > complexity, but that should be hidden from users. They will not need to > care about the internals. They will be able to forget about 'narrow' > versus 'wide' builds and the possible requirement to code differently > for each. There will only be one scheme that works the same on all > platforms. Most apps should require less space and about the same time. > > -- Python 2 was built for ascii users. Now, Python 3(.3) is *optimized* for the ascii users. And the rest of the crowd? Not so sure, French users (among others) who can not write their texts will iso-8859-1/latin1 will be very happy. No doubts, it will work. Is this however the correct approach? jmf -- http://mail.python.org/mailman/listinfo/python-list
Override the interpreter used by multiprocessing subprocesses?
Hello, I am using a product that has a built-in Python interpreter (ESRI ArcGIS Desktop 10.0 SP3) and have implemented multiprocessing in script that can be run by a tool within the application using the built-in interpreter. The way the built-in interpreter works is incompatible with multiprocessing as it appears to want to start multiple instances of the host application when the subprocesses are created. I am using multiprocessing.Pool with the apply_async function. It works great in a standalone script and I'd rather not rewrite what I've done so far if I can help it, but if there is a way to simply force the standard interpreter to be used for the subprocesses that would be ideal. Thinking about it I realize that this might not be possible due to whatever messaging, pickling, and queueing that the main processes has to handle for the subprocesses, but thought I would ask anyways if only for my own enlightenment. TIA! -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
On Mon, 13 Feb 2012 13:01:05 -0800 (PST) Rick Johnson wrote: > On Feb 13, 12:38 pm, Ian Kelly wrote: > > I hate being suckered in by trolls, but this paragraph demands a response. Ditto... > > On Mon, Feb 13, 2012 at 9:01 AM, Rick Johnson > > > > wrote: > > > You are born with rights. Life, Liberty, and the pursuit of happiness. > > > Healthcare care is NOT a right, healthcare is a privileged. [...] > HOWEVER, healthcare is not a concern of the greater society, but only > the individual -- with the exception of contagious disease of course, [...snip half-baked, social-Darwinist, "there-is-no-such-thing-as-society", naive U.S.-capitalist-libertarian drivel...] > > > Procreation should be a > > > privilege, however sadly for our collective evolution, it's seems to > > > be a right :( > > > > There is a word for the philosophy that procreation should be a > > privilege reserved for those with good genes: eugenics. > > No, the word is evolution; which means: "survival of the fittest". > Don't try to hijack real science to bolster a repugnant ideology. Neither Herbert Spencer nor Darwin meant that phrase the way you do. [...snip egregious, self-serving display of ignorance on the subjects of evolution and genetics...] > > > Welcome to fascism, Rick. > > Don't try to append me onto a specific ideology structure just because > that group happens to support ONE of my beliefs. I carry no political [...blah blah...] It's called duck-typing. I somewhat optimistically implore you, Rick, to do some basic research on your chosen subjects. Failing that (almost certainly), here are three simple points which debunk your agenda (and that of the U.S. Republican Right): 1. Publicly-funded healthcare is both cheaper and more effective than privatised systems. It's also the right thing to do (i.e. you don't have to stand by while someone dies because their illness is "their fault"). Which makes it a win-win-win. 2. The recent economic problems were not triggered by "degenerates" (are you actually talking about homosexuals here, or just in the more general, McCathyist sense?), but in fact by the operations of the same unregulated markets you are advocating. 3. The central fallacy of social Darwinism is the misapprehension that because natural selection occurs in nature, human society _should_ also work this way. This is a failure to acknowledge the is/ought problem, and is usually compounded (Rick is no exception) by the equally mistaken view that there exist "superior" individuals whose possession of a "quality gene-pool" entitles them to survival - an entitlement that is encroached upon by inferior sorts who take up space by insisting on not dying. Can you guess in which group those who hold this view place themselves? In fact, a gene pool is held by a species, not an individual, and the maintenance of its diversity is essential for long term-survival. And to the great disappointment of those looking for a justification of dog-eat-dog, one of the main drivers of evolution is not competition, but adapting to new environments to _avoid_ competition. I'm told the Spanish have a saying which translates as "dogs don't eat dogs". Genetics is complicated. Switching one gene on switches others off in unpredictable ways, people choose mates by unfathomable processes, good-looking geniuses have dumb, ugly children and vice-versa. This is why eugenics projects are doomed to failure. They are also morally wrong, which is another win-win. If some featureless fungus, toxic to all other living things, engulfed the globe, would that make it "superior"? Of course, not, it merely survived. Considerations of what _should_ happen, of superiority and quality, are human, social concerns. We are humans, so they are important to us. But they have nothing to do with genetics or evolution. Social Darwinism is merely a psuedo-scientific attempt to justify inequity and class divides. Furthermore, it is completely dead outside the U.S. - ironically the only developed nation where real Darwinism is still seriously questioned. [...] > Go on believing that humans will be inhabiting this rock in > the next 1000 years, or this universe in the next 10,000 -- because > the enlightened few will have transcended into the mind hive and your @ > $$ will be glued to Terra firma forever! Now that is some crazy shit! Maybe L. Ron _is_ still alive... Regards, John -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
(Sorry for top-posting this bit, but I think it's required before the rest of my response) At the risk of wading into this from a UK citizen's perspective: You're imagining a public healthcare system as if it were private. Imagine you go to a doctor and say "I've got the flu, can you give me antibiotics". In a Private healthcare system: * The doctor gets paid for retaining a client. * He is incentivised to do what you request. ... so he gives you the antibiotics. In a Public healthcare system: * The doctor is paid no matter what. * His job is to stop the population becoming ill. * By reducing illnesses he reduces his workload, without reducing his wage ... so he'll only give you antibiotics if he feels you are at serious risk, and giving you antibiotics carries less risk for the population than the risk of the population getting immunities. Same goes for surgery etc. On Mon, 2012-02-13 at 08:01 -0800, Rick Johnson wrote: > And just how much healthcare dollars are you entitled to exactly? Can > you put your entitlement into some form of monetary value? > > And how can we ever make a system like this fair? If someone works for > 30 years and pays a 30% tax rate and another works for 2 years and > pays 15%, then how do we delegate the fair share? If your children are educated privately then should you still be paying taxes for education? If you work for/bank with a company that doesn't need to be bailed out, then should you still pay tax for that? If you never need benefits (welfare) then should your taxes be paying for that? you can use that same argument for everything that taxes pay for - the only logical conclusion of that argument is anarchy (i.e. no taxes, and no government). If you are an anarchist then that's a different argument all together (not saying it doesn't have intellectual validity). > Healthcare is expensive. Do you want a minimum wage doctor curing your > ills? And the frivolous lawsuits are not bringing the costs down > either. It's so expensive because of the marketing, and because of all the middle-men. A public health system doesn't need to do that marketing. They also don't need to put up with people who aren't seriously ill - I don't know how long your private appointments are, but here in the UK a standard doctor's appointment is 5-10 minutes. If they decide you're actually ill they may extend that. > > - bosses win, because they have reduced absenteeism, lower training costs > > to replace workers who die, and fewer epidemics that threaten their own > > families > > BS! With free healthcare, those who would have allowed their immune > system fight off the flu, now take off from work, visit a local > clinic, and get pumped full of antibiotics so they can create a new > strain of antibiotic resistant flu virus! Thanks free healthcare! See my comments at the top. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to tell a method is classmethod or static method or instance method
On 14Feb2012 13:13, Zheng Li wrote: | > On 13Feb2012 15:59, Zheng Li wrote: | > | how to tell a method is class method or static method or instance method? | > | > Maybe a better question is: | > under what circumstances do you need to figure this out? | | I can get "method1" of class "Test" by | a = getattr(Test, "method1") | | and I also want know how to invoke it | a() or a(Test()) Normally: a(T) where T is an object of type/class Test. So your second approach is notionally correct (aside from making a throwaway object that is then discarded). | BTW: | I don't see what the problem is if I ask a question just because I am curious about it. There's nothing wrong with it at all. But often, questions arise from some other circumstances and this one is of such a flavour that if you wanted this code in a real application it would _often_ be the wrong solution to seek, because normally you know how to call something - it is not normally useful to introspect it to decide what to do. So I was wondering what the outer context might be, because there may well have been a better solution to the situation that brought up the specific question. Simple curiosity is sufficient reason, of course. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Too young to rest on the weekend, too old to rest during the week. - Mark Randol -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
Rick Johnson wrote: > BS! With free healthcare, those who would have allowed their immune > system fight off the flu, now take off from work, visit a local > clinic, and get pumped full of antibiotics so they can create a new > strain of antibiotic resistant flu virus! Thanks free healthcare! Anyone who can write 'antibiotic resistant flu virus' as though they believe it really needs to read some elementary books about disease. Here's a clue: No flu viruses are treatable with antibiotics. In some cases antibiotics may be useful for flu patients to treat secondary bacterial infections, but they are not effective against viruses. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
On Tue, Feb 14, 2012 at 6:31 AM, Duncan Booth wrote: > Here's a clue: No flu viruses are treatable with antibiotics. Oh my god we're too late! Now they're ALL resistant! -- Devin -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
On Feb 13, 9:01 pm, Rick Johnson wrote: > > And just how much healthcare dollars are you entitled to exactly? Can > you put your entitlement into some form of monetary value? Rick hats off to you man -- you are damn good! Did you study at a top- troll-school? eg. http://www.youtube.com/watch?v=FMEe7JqBgvg -- http://mail.python.org/mailman/listinfo/python-list
Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?
On Feb 14, 4:38 am, Devin Jeanpierre wrote: > Hey Pythonistas, > > Consider the regular expression "$*". Compilation fails with the > exception, "sre_constants.error: nothing to repeat". > > Consider the regular expression "(?=$)*". As far as I know it is > equivalent. It does not fail to compile. > > Why the inconsistency? What's going on here? > > -- Devin $ is a meta character for regular expressions. Use '\$*', which does compile. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?
On Tue, Feb 14, 2012 at 8:20 AM, Vinay Sajip wrote: > $ is a meta character for regular expressions. Use '\$*', which does > compile. I mean for it to be a meta-character. I'm wondering why it's OK for to repeat a zero-width match if it is a zero-width assertion. -- Devin -- http://mail.python.org/mailman/listinfo/python-list
name of a sorting algorithm
Hi, Could someone please tell me what the following sorting algorithm is called? Let an array contain the elements a_1, a_2, ..., a_N. Then: for i = 1 to N-1: for j = i+1 to N: if a_j < a_i then swap(a_j, a_i) It's so simple that it's not mentioned anywhere. I guess it's called "selection sort" but I'm not sure. The minimum selection sort is an improvement of this one. Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?
2012/2/14 Devin Jeanpierre : > Hey Pythonistas, > > Consider the regular expression "$*". Compilation fails with the > exception, "sre_constants.error: nothing to repeat". > > Consider the regular expression "(?=$)*". As far as I know it is > equivalent. It does not fail to compile. > > Why the inconsistency? What's going on here? > > -- Devin > -- > http://mail.python.org/mailman/listinfo/python-list Hi, I don't know the reason for the observed differences either (I can think of some optimisation issues etc.), but just wanted to mention some other similar patterns to your lookahaed: It seems, that groups (capturing or not capturing) also work ok: >>> re.findall("($)*", "abc") ['', '', '', ''] >>> re.findall("(?:$)*", "abc") ['', '', '', ''] However, is there any realistic usecase for repeated zero-width anchors? regards, vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: Automatic Type Conversion to String
Am 14.02.2012 00:18, schrieb Bruce Eckel: I'm willing to subclass str, but when I tried it before it became a little confusing -- I think mostly because anytime I assigned to self it seemed like it converted the whole object to a str rather than a Path. I suspect I don't know the proper idiom for doing this -- any hints? Thanks ... Could it be that you missed the fact that strings are immutable? That means that you can't change the content of the object once it is initialized. In particular, it means that you e.g. have to override __new__ instead of __init__, because the content is already fixed when the latter is called. Python strings rather behave like Java strings than C++ strings. Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: name of a sorting algorithm
Jabba Laci wrote: > Could someone please tell me what the following sorting algorithm is > called? > > Let an array contain the elements a_1, a_2, ..., a_N. Then: > for i in xrange (N-1): for j in xrange (i, N): if a[j] < a[i]: a[i], a[j] = a[j], a[i] > > It's so simple that it's not mentioned anywhere. I guess it's called > "selection sort" but I'm not sure. The minimum selection sort is an > improvement of this one. It's what Wikipedia says a selection sort is: put the least element in [0], the least of the remaining elements in [1], etc. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?
On Tue, Feb 14, 2012 at 10:05 AM, Vlastimil Brom wrote: > However, is there any realistic usecase for repeated zero-width anchors? Maybe. There is a repeated zero-width anchor is used in the Python re test suite, which is what made me notice this. I assume that came from some actual use-case. (see: http://hg.python.org/cpython/file/096e856a01aa/Lib/test/test_re.py#l599 ) And yeah, even something as crazy as ()* works, but as soon as it becomes (a*)* it doesn't work. Weird. -- Devin -- http://mail.python.org/mailman/listinfo/python-list
RE: name of a sorting algorithm
> for i in xrange (N-1): for j in xrange (i, N): if a[j] < a[i]: a[i], a[j] = a[j], a[i] > It's what Wikipedia says a selection sort is: put the least element in [0], > the least of the remaining elements in [1], etc. If your only requirement to match to selection sort is the end result, then every sort would be selection sort. If you meant "put the least element in [0] in the first pass" then that would indeed be selection sort, but that is not what the above code does. The above code is bubble sort. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: name of a sorting algorithm
Am 14.02.2012 16:01, schrieb Jabba Laci: Could someone please tell me what the following sorting algorithm is called? Let an array contain the elements a_1, a_2, ..., a_N. Then: for i = 1 to N-1: for j = i+1 to N: if a_j< a_i then swap(a_j, a_i) It's so simple that it's not mentioned anywhere. Please do your own homework. This code isn't even Python! I guess it's called "selection sort" but I'm not sure. You guessed right. Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: name of a sorting algorithm
On 14 February 2012 15:31, Dennis Lee Bieber wrote: > On Tue, 14 Feb 2012 16:01:05 +0100, Jabba Laci > wrote: > >>Could someone please tell me what the following sorting algorithm is called? >> >>Let an array contain the elements a_1, a_2, ..., a_N. Then: >> >>for i = 1 to N-1: >> for j = i+1 to N: >> if a_j < a_i then swap(a_j, a_i) >> > Off hand... The ancient Bubble-Sort... > > http://en.wikipedia.org/wiki/Bubble_sort Ahem... No, it's not Bubble Sort. Bubble sort only swaps adjacent terms. I don't know what this sort is called, if it even has a name. It's a kind of Selection Sort, as each pass it looks for the minimum of the remaining unsorted items. But it ruffles the unsorted list each pass, seemingly to save using an extra register to store the current minumum (there was a time when registers were at a premium). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
RE: name of a sorting algorithm
Prasad, Ramit wrote: >> > for i in xrange (N-1): > for j in xrange (i, N): > if a[j] < a[i]: > a[i], a[j] = a[j], a[i] >> It's what Wikipedia says a selection sort is: put the least element in >> [0], the least of the remaining elements in [1], etc. > > If your only requirement to match to selection sort is the end result, > then every sort would be selection sort. If you meant "put the least > element in [0] in the first pass" then that would indeed be selection > sort, but that is not what the above code does. The above code is bubble > sort. Well, the classic bubble sort swaps adjacent elements until the extreme one gets all the way to the end. This sort continually swaps with the end element during one pass until the end element holds the extreme. Then it shrinks the range and swaps then next less extreme into the new end element. It does extra swaps because it combines the swap operation with recording the temporary extreme while it searches the subrange. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: name of a sorting algorithm
On Feb 14, 8:22 am, Arnaud Delobelle wrote: > On 14 February 2012 15:31, Dennis Lee Bieber wrote: > > > On Tue, 14 Feb 2012 16:01:05 +0100, Jabba Laci > > wrote: > > >>Could someone please tell me what the following sorting algorithm is called? > > >>Let an array contain the elements a_1, a_2, ..., a_N. Then: > > >>for i = 1 to N-1: > >> for j = i+1 to N: > >> if a_j < a_i then swap(a_j, a_i) > > > Off hand... The ancient Bubble-Sort... > > >http://en.wikipedia.org/wiki/Bubble_sort > > Ahem... > > No, it's not Bubble Sort. Bubble sort only swaps adjacent terms. > > I don't know what this sort is called, if it even has a name. It's a > kind of Selection Sort, as each pass it looks for the minimum of the > remaining unsorted items. But it ruffles the unsorted list each pass, > seemingly to save using an extra register to store the current minumum > (there was a time when registers were at a premium). > > -- > Arnaud I disagree. In a bubble sort, one pointer points to the top element, while another descents through all the other elements, swapping the elements at the pointers when necessary. Then the one pointer moved down to the next element and the process repeats. This looks like the bubble sort to me. It was one of the first algorithms I had to program in my first programming class in 1969. Den -- http://mail.python.org/mailman/listinfo/python-list
Re: name of a sorting algorithm
Den wrote: > I disagree. In a bubble sort, one pointer points to the top element, > while another descents through all the other elements, swapping the > elements at the pointers when necessary. 'When I use a word,' Humpty Dumpty said, in rather a scornful tone, 'it means just what I choose it to mean — neither more nor less.' (_Through the Looking Glass, Lewis Caroll). And you, too, have that ability. Contrariwise see Knuth, _The Art of Computer Programming_ Section 5.2.2, Algorithm B. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: name of a sorting algorithm
On Tue, Feb 14, 2012 at 9:55 AM, Den wrote: > On Feb 14, 8:22 am, Arnaud Delobelle wrote: >> On 14 February 2012 15:31, Dennis Lee Bieber wrote: >> >> > On Tue, 14 Feb 2012 16:01:05 +0100, Jabba Laci >> > wrote: >> >> >>Could someone please tell me what the following sorting algorithm is >> >>called? >> >> >>Let an array contain the elements a_1, a_2, ..., a_N. Then: >> >> >>for i = 1 to N-1: >> >> for j = i+1 to N: >> >> if a_j < a_i then swap(a_j, a_i) >> >> > Off hand... The ancient Bubble-Sort... >> >> >http://en.wikipedia.org/wiki/Bubble_sort >> >> Ahem... >> >> No, it's not Bubble Sort. Bubble sort only swaps adjacent terms. >> >> I don't know what this sort is called, if it even has a name. It's a >> kind of Selection Sort, as each pass it looks for the minimum of the >> remaining unsorted items. But it ruffles the unsorted list each pass, >> seemingly to save using an extra register to store the current minumum >> (there was a time when registers were at a premium). >> >> -- >> Arnaud > > I disagree. In a bubble sort, one pointer points to the top element, > while another descents through all the other elements, swapping the > elements at the pointers when necessary. Then the one pointer moved > down to the next element and the process repeats. This looks like the > bubble sort to me. It was one of the first algorithms I had to > program in my first programming class in 1969. Either you're misremembering, or the algorithm you programmed 43 years ago was not actually bubble sort. Quoting from Wikipedia: """ Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. """ In the present algorithm, you'll note that elements in the unsorted part of the list do not "bubble up" as they would in bubble sort. Rather, they jump around somewhat randomly until they are finally selected for the current sort index. I agree with Arnaud -- this is a selection sort variant that saves a local variable (the index of the minimum element) by placing it at the current sort index instead -- at the cost of doing additional swaps. Probably not a good trade-off in Python (but then again, no pure Python sort algorithm is likely to perform better than the built-in). Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?
On 14/02/2012 15:53, Devin Jeanpierre wrote: On Tue, Feb 14, 2012 at 10:05 AM, Vlastimil Brom wrote: However, is there any realistic usecase for repeated zero-width anchors? Maybe. There is a repeated zero-width anchor is used in the Python re test suite, which is what made me notice this. I assume that came from some actual use-case. (see: http://hg.python.org/cpython/file/096e856a01aa/Lib/test/test_re.py#l599 ) And yeah, even something as crazy as ()* works, but as soon as it becomes (a*)* it doesn't work. Weird. I think it's a combination of warning the user about something that's pointless, as in the case of "$*", and producing a pattern which could cause the internal regex engine to get stuck in an infinite loop. It is inconsistent in that it warns about "$*" but not "(?=$)*" even though they are basically equivalent. -- http://mail.python.org/mailman/listinfo/python-list
Re: name of a sorting algorithm
Hi, > Either you're misremembering, or the algorithm you programmed 43 years > ago was not actually bubble sort. Quoting from Wikipedia: > > """ > Bubble sort, also known as sinking sort, is a simple sorting algorithm > that works by repeatedly stepping through the list to be sorted, > comparing each pair of adjacent items and swapping them if they are in > the wrong order. The pass through the list is repeated until no swaps > are needed, which indicates that the list is sorted. The algorithm > gets its name from the way smaller elements "bubble" to the top of the > list. > """ I don't agree with the last sentence. During bubble sort, in the 1st pass the largest element is moved to the top (for me "top" means the right side (end) of an array). Thus the end of the array is sorted. In the 2nd pass, the largest element of the unsorted left part is moved to the end, etc. That is, it's the _larger_ elements that bubble to the top. At http://en.wikipedia.org/wiki/Bubble_sort you can find an animated gif that shows how the algorithm works. > In the present algorithm, you'll note that elements in the unsorted > part of the list do not "bubble up" as they would in bubble sort. > Rather, they jump around somewhat randomly until they are finally > selected for the current sort index. I agree with Arnaud -- this is a > selection sort variant that saves a local variable (the index of the > minimum element) by placing it at the current sort index instead -- at > the cost of doing additional swaps. Probably not a good trade-off in > Python (but then again, no pure Python sort algorithm is likely to > perform better than the built-in). The minimum selection sort is an improvement of this "noname" algorithm. I give it in pseudo-code. Let A be an array with N elements. Indexing starts with 1. for i := 1 to N-1: minindex := i for j := i+1 to N: if A[j] < A[minindex] then minindex := j end for if i != minindex then swap(A[i], A[minindex]) end for The two loops are the same as in the naive version. It will also sort the array from the left side. It does much less swaps than the naive version. If the "noname" algorithm is called "selection sort", then its name can be misleading. One may ask "OK, but which one? Minimum or maximum selection sort?". Well, neither... Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Komodo 7 release (Python development tools)
On 12-02-08 01:52 PM, Terry Reedy wrote: On 2/8/2012 3:14 PM, Todd Whiteman wrote: My name is Todd. I'm the lead developer for Komodo IDE (Interactive Development Environment) and Komodo Edit (a free, open-source editor) at ActiveState. I wanted to announce that the newest version, Komodo 7, has been released: http://www.activestate.com/komodo-ide/python-editor It would seem that the Professional Python Editor is the same as Komodo Edit, but it is unclear why only Python editing would be featured for Komodo IDE. http://www.activestate.com/komodo-edit is the page with the link people need to download just the editor. The above page covers features from both Edit and IDE - some will only apply to the IDE version. For a full comparison of features you can check out: http://www.activestate.com/komodo-edit/compare-with-komodo-ide Does K.Edit let me run a program with one key, like F5 in IDLE? If so, does it leave me in interactive mode (python -i) as IDLE does? Komodo Edit does not offer a quick run (F5) command by default, you could create your own Python command [1] in the Komodo toolbox and assign it the F5 key binding to serve such a purpose. [1] The short command for running a Python script is: "%(python) %F", which uses Komodo's interpolation shortcuts: http://docs.activestate.com/komodo/7.0/shortcuts.html#shortcuts_top Cheers, Todd -- http://mail.python.org/mailman/listinfo/python-list
RE: name of a sorting algorithm
Prasad, Ramit wrote: > My apologies, you are correct. It is a selection sort, just an inefficient > one. Hmm, I think I should say it is neither since it reminds me of a hybrid of both (bubble/selection). The swapping seems very bubble sort, but the looking for the min / max case seems selection sort-ish. Whatever it is, it is certainly inefficient. :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: name of a sorting algorithm
Wilson, Mel wrote: >Well, the classic bubble sort swaps adjacent elements until the extreme one >gets all the way to the end. This sort continually swaps with the end >element during one pass until the end element holds the extreme. Then it >shrinks the range and swaps then next less extreme into the new end element. >It does extra swaps because it combines the swap operation with recording >the temporary extreme while it searches the subrange. My apologies, you are correct. It is a selection sort, just an inefficient one. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: name of a sorting algorithm
On Tue, Feb 14, 2012 at 11:10 AM, Jabba Laci wrote: > Hi, > >> Either you're misremembering, or the algorithm you programmed 43 years >> ago was not actually bubble sort. Quoting from Wikipedia: >> >> """ >> Bubble sort, also known as sinking sort, is a simple sorting algorithm >> that works by repeatedly stepping through the list to be sorted, >> comparing each pair of adjacent items and swapping them if they are in >> the wrong order. The pass through the list is repeated until no swaps >> are needed, which indicates that the list is sorted. The algorithm >> gets its name from the way smaller elements "bubble" to the top of the >> list. >> """ > > I don't agree with the last sentence. During bubble sort, in the 1st > pass the largest element is moved to the top (for me "top" means the > right side (end) of an array). Thus the end of the array is sorted. In > the 2nd pass, the largest element of the unsorted left part is moved > to the end, etc. That is, it's the _larger_ elements that bubble to > the top. At http://en.wikipedia.org/wiki/Bubble_sort you can find an > animated gif that shows how the algorithm works. I think that by "top" they mean "front". Each largest element in turn gets moved to the end in a single pass. It is the smaller elements gradually moving toward the front over many passes that I believe is described as "bubbling", as can be seen in that gif. > If the "noname" algorithm is called "selection sort", then its name > can be misleading. One may ask "OK, but which one? Minimum or maximum > selection sort?". Well, neither... It is a minimum selection sort, because it selects the minimum element on each pass. It just stores the minimum element so far in-place in the array, rather than in a separate variable. -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
On Feb 14, 2:41 am, John O'Hagan wrote: > > 1. Publicly-funded healthcare is both cheaper and more effective than > privatised systems. It's also the right thing to do (i.e. you don't have > to stand by while someone dies because their illness is "their fault"). So you have no problem paying the medical bills of people who overeat sugar, salt, and fat; refuse to put down the ho-ho's; and get a little exercise? If so, then give to charity. Why do you need to FORCE me (and others) to pay for your experiment of "degenerate eugenics"? > 2. The recent economic problems were not triggered by "degenerates" (are you > actually talking about homosexuals here, or just in the more general, > McCathyist sense?) WTF does homosexuality have to do with this conversation? I am talking about lazy/slothful, drug/alcohol abusing, junk food eating, self- induced illiterates, techno-phobic Luddite loving lemmings. Look, i don't care how you want to live YOUR life, just leave me and my money the hell out of it! >, but in fact by the operations of the same unregulated > markets you are advocating. I am well aware of the sins of wall street and the ruling "corporate class" (Greed.inc). That is half the problem, yes. However, you cannot ignore the fact that we are spending trillions around the globe supporting degenerates. Look at Detroit MI. People like to blame GM for the state of the city but GM is only a very small part of the problem. The REAL problem is sleazy politicians and infections entitlements/welfare. When you crush the tax payers with more and more tyrannical taxation to pay for your entitlement programs, the taxpayers leave town; but the welfare recipients stay! Why the heck would they quit a good thing? However, now you find yourself in a major pickle. With the taxpayers gone, who's going to fund the entitlement programs? NOBODY! The whole house of cards comes crumbling down! Of course i'm probably just wasting my time trying to educate you. You'll just blab on and on about how evil i am for not paying other people's bills so they can watch there hero degenerates on Jersey Shore. > 3. The central fallacy of social Darwinism is the misapprehension that because > natural selection occurs in nature, human society _should_ also work this > way. I NEVER said we should adopt such a society. That is anarchy. And anarchy will NEVER move us forward as a species. > This is a failure to acknowledge the is/ought problem, and is usually > compounded (Rick is no exception) by the equally mistaken view that there > exist > "superior" individuals whose possession of a "quality gene-pool" entitles them > to survival - an entitlement that is encroached upon by inferior sorts who > take > up space by insisting on not dying. Can you guess in which group those who > hold > this view place themselves? You'd be surprised which group i reside in. I know my place; but do you know yours? > Genetics is complicated. Switching one gene on switches others off in > unpredictable ways, people choose mates by unfathomable processes, > good-looking > geniuses have dumb, ugly children and vice-versa. This is why eugenics > projects > are doomed to failure. They are also morally wrong, which is another win-win. There is nothing wrong with denying degenerates the right to reproduce. Would you allow a crack head to reproduce? How about someone who carries a virus/illness/deadly defect for which there is no cure and the virus/illness/deadly defect will be passed on to the child? What if you knew without a doubt the baby would be born with two heads, or mentally incapacitated, or brain dead, or etc...? Would you allow the procreation anyway simply because people have a right to be selfish? What if the couple was healthy but had poor parenting skills, or cannot feed the child, or cannot cloth the child, or etc...? Would you allow the procreation anyway simply because people have a right to be selfish? What abut people who go around making babies but refuse to care for them at all? I mean, birth control has been around for some time, but we can't force degenerates to use it! Would you allow the procreation anyway simply because people have a right to be selfish? > If some featureless fungus, toxic to all other living things, engulfed the > globe, would that make it "superior"? Of course, not, it merely survived. I love when people contradict themselves in the same sentence -- makes my job much easier! > Considerations of what _should_ happen, of superiority and quality, are human, > social concerns. We are humans, so they are important to us. But they have > nothing to do with genetics or evolution. Really??? I think you need to spend more time ruminating on the subject. You can stick your head in the sand if you like, but technology will advance with or without you. Humans will be cloned. Humans will be genetically engineered. Humans will employ eugenics to sculpt the gene pool. It is our destiny to use our intelligence to drive o
Re: OT: Entitlements [was Re: Python usage numbers]
On Wed, Feb 15, 2012 at 11:21 AM, Rick Johnson wrote: > On Feb 14, 2:41 am, John O'Hagan wrote: >> This is a failure to acknowledge the is/ought problem, and is usually >> compounded (Rick is no exception) by the equally mistaken view that there >> exist >> "superior" individuals whose possession of a "quality gene-pool" entitles >> them >> to survival - an entitlement that is encroached upon by inferior sorts who >> take >> up space by insisting on not dying. Can you guess in which group those who >> hold >> this view place themselves? > > You'd be surprised which group i reside in. I know my place; but do > you know yours? If you truly believe that only the best should be allowed to survive and that you are not of the best, then the logical thing to do is to immediately destroy yourself. Oddly enough, though, I don't see many eugenics proponents committing mass suicide for the benefit of the gene pool. > There is nothing wrong with denying degenerates the right to > reproduce. Actually there is; I'm fairly sure that I wouldn't have been born if such policies had been in place, and I strongly suspect that you wouldn't have either. There was a country in the 20th century that adopted a lot of the sorts of policies you're talking about, and it's such a sensitive topic with MANY people that I'm not going to touch it. Suffice it to say that the world does not appreciate such things. >> If some featureless fungus, toxic to all other living things, engulfed the >> globe, would that make it "superior"? Of course, not, it merely survived. > > I love when people contradict themselves in the same sentence -- makes > my job much easier! No, he did not contradict himself - he drew a distinction between "superior" and "survived". You might argue that your definition of "superior" *is* the ability to survive, but that's a matter for logical argument, not for pointing and laughing. > It is our destiny to use our intelligence to > drive our own evolution at an ever accelerating rate. To NOT use that > power would be to spit in the face of evolution itself! Evolution is driven by the survival of the fittest, not by us using our intelligence to influence it. It's high time I stood up for who I am. I *do* spit in the face of evolution. I do not believe that we came here because we evolved from some lesser life-form, and I do not believe that the world is best served by such philosophies. God created us, roughly 6000-1 years ago, and since then, many things have happened (both good and bad), but never has there been the emergence of any form of "next-species human". Look at history (just recent history if you like - the last few hundred years) and find the times when one group of people deemed themselves "more evolved" than another group. Why were Negros treated as slaves in the US? Why were Australian Aboriginals treated like animals? And the one I hinted at above. If you truly believe that evolution is the way forward, then go find some of the lobbyists for these groups, and say to their faces that you believe that some humans are lesser than others. If you come out of that alive, report back. Preferably with video. It should be interesting. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
On Feb 13, 10:41 am, Tim Wintle wrote: > Imagine you go to a doctor and say "I've got the flu, can you give me > antibiotics". > > In a Private healthcare system: > > * The doctor gets paid for retaining a client. > * He is incentivised to do what you request. > ... so he gives you the antibiotics. > > In a Public healthcare system: > * The doctor is paid no matter what. > * His job is to stop the population becoming ill. > * By reducing illnesses he reduces his workload, without reducing his > wage > > ... so he'll only give you antibiotics if he feels you are at serious > risk, and giving you antibiotics carries less risk for the population > than the risk of the population getting immunities. Of all the great arguments i have presented you choose the minor "antibiotic comment" and run with it? But you take NO position on "supporting the degenerates of society"? Would you mind making your position known? You see, you can have all the healthcare and healthcare dollars in the world. But if your patient keeps eating greasy hamburgers, salty/oily french fries, and blood-sugar spiking soda-pops, he is going to die a nasty death! Sadly however, he will live for many years in a state of poor heath before finally "kicking the bucket". All the while draining the system of resources and money. > [...] > you can use that same argument for everything that taxes pay for - the > only logical conclusion of that argument is anarchy (i.e. no taxes, and > no government). > > If you are an anarchist then that's a different argument all together > (not saying it doesn't have intellectual validity). I am not an anarchist. Stop trying to label me. > > Healthcare is expensive. Do you want a minimum wage doctor curing your > > ills? And the frivolous lawsuits are not bringing the costs down > > either. > > It's so expensive because of the marketing, and because of all the > middle-men. You're thinking of pharmaceuticals NOT healthcare. And while marketing is a large expense for pharmaceutical companies; R&D, lawsuits, and brown-nosing are the main cost of doing buisness. > They also don't need to put up with people who aren't seriously ill - I > don't know how long your private appointments are, but here in the UK a > standard doctor's appointment is 5-10 minutes. If they decide you're > actually ill they may extend that. Five to ten minutes? Is the doctor an a-hole or a machine? Can a doctor REALLY diagnose an illness in five to ten minutes? Are you joking? And if not, do you ACTUALLY want the experience to be synonymous with an assembly line? You don't fear misdiagnosis? I envy your bravery! -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
On Feb 14, 5:31 am, Duncan Booth wrote: > Rick Johnson wrote: > > BS! With free healthcare, those who would have allowed their immune > > system fight off the flu, now take off from work, visit a local > > clinic, and get pumped full of antibiotics so they can create a new > > strain of antibiotic resistant flu virus! Thanks free healthcare! > > Anyone who can write 'antibiotic resistant flu virus' as though they > believe it really needs to read some elementary books about disease. > > Here's a clue: No flu viruses are treatable with antibiotics. In some cases > antibiotics may be useful for flu patients to treat secondary bacterial > infections, but they are not effective against viruses. Duncan, your reading and comprehension skills are atrocious. Please re- read the paragraph you quoted, then spend some time "comprehending" it, then show me where i stated that "antibiotics cure viral infections". psst: i NEVER said any such thing! My point is: these "quacks" are prescribing antibiotics when people don't even need them! Such disregard for immunity is frightening. Penicillin was a gift from the gods, and we have squandered it! Thanks free healthcare! -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
On Wed, Feb 15, 2012 at 11:48 AM, Rick Johnson wrote: > Duncan, your reading and comprehension skills are atrocious. Please re- > read the paragraph you quoted, then spend some time "comprehending" > it, then show me where i stated that "antibiotics cure viral > infections". psst: i NEVER said any such thing! I'm not sure how you'd go about creating a new strain of a virus that's resistant to antibiotics, unless the previous strain was NOT resistant. Viruses are _immune_ to antibiotics, and as we know from Angband, immunity equals resistance times ten. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
On Feb 14, 6:44 pm, Chris Angelico wrote: > If you truly believe that only the best should be allowed to survive > and that you are not of the best, then the logical thing to do is to > immediately destroy yourself. Oddly enough, though, I don't see many > eugenics proponents committing mass suicide for the benefit of the > gene pool. I don't need to destroy myself Chris. Likewise i don't need to destroy anyone else. You are trying to cast me as an evil blood thirsty person, and i can assure you, i am not. All i need to do is NOT reproduce and i've done my part. Likewise all WE need to do is keep the rest "of us" from reproducing. I am not a degenerate, but my genes are flawed. All i can hope to do is make an intellectual contribution to our evolution as a species. Just because you're flawed in one area, does not mean you cannot make contributions in other areas. You can still be part of the whole -- AS LONG AS YOU UNDERSTAND YOUR PLACE! > > There is nothing wrong with denying degenerates the right to > > reproduce. > > Actually there is; I'm fairly sure that I wouldn't have been born if > such policies had been in place, and I strongly suspect that you > wouldn't have either. So what's the problem with that? > There was a country in the 20th century that > adopted a lot of the sorts of policies you're talking about, and it's > such a sensitive topic with MANY people that I'm not going to touch > it. Suffice it to say that the world does not appreciate such things. Of course people don't want to admit that they don't belong, or that they are flawed, or that they are inferior. We are "wired" with egos so that we don't purposely destroy ourselves; which is vital to our "collective" evolution, but NOT our individual evolution. However, like all software, the definitions don't always cover the corner cases. Only WE, as intelligent beings, can compensate for the missing code in our own software. Evolution is just a system. A very dumb system. We are the only hope for evolution beyond what this base system can create. We must take the reigns and drive our own evolution. > >> If some featureless fungus, toxic to all other living things, engulfed the > >> globe, would that make it "superior"? Of course, not, it merely survived. > > > I love when people contradict themselves in the same sentence -- makes > > my job much easier! > > No, he did not contradict himself - he drew a distinction between > "superior" and "survived". You might argue that your definition of > "superior" *is* the ability to survive, but that's a matter for > logical argument, not for pointing and laughing. "If" a fungus did in fact "engulf the earth", THEN it MUST be superior! > > It is our destiny to use our intelligence to > > drive our own evolution at an ever accelerating rate. To NOT use that > > power would be to spit in the face of evolution itself! > > Evolution is driven by the survival of the fittest, not by us using > our intelligence to influence it. But WE are the fittest! Because we are INTELLIGENT! > God created us, roughly 6000-1 years ago, and since then, many > things have happened (both good and bad), but never has there been the > emergence of any form of "next-species human". Look at history (just > recent history if you like - the last few hundred years) and find the > times when one group of people deemed themselves "more evolved" than > another group. Why were Negros treated as slaves in the US? Because they allowed themselves to be subjected. Sad, but true. > Why were > Australian Aboriginals treated like animals? Because they allowed them selves to be subjected. Sad, but true. > And the one I hinted at > above. Because the Jews allowed themselves to be subjected. Sad, but true. Slaves only exist because they allow themselves to exist. When people fight back against tyranny, tyranny fails. When people subject themselves to tyranny, tyranny prospers. There have been many instances in history where people did not allow themselves to be subjected; William Wallace comes to mind. "Freedmmm!" "Live free, or die!" "From my cold dead hand!" "Over my dead body!" "Freedom is never voluntarily given by the oppressor; it must be demanded by the oppressed." "Those who deny freedom to others deserve it not for themselves." "Man is free at the moment he wishes to be." "Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one." -- http://mail.python.org/mailman/listinfo/python-list
Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?
On Tue, Feb 14, 2012 at 1:05 PM, MRAB wrote: >> And yeah, even something as crazy as ()* works, but as soon as it >> becomes (a*)* it doesn't work. Weird. >> > I think it's a combination of warning the user about something that's > pointless, > as in the case of "$*", and producing a pattern which could cause the > internal > regex engine to get stuck in an infinite loop. Considering that ()* works fine, I can't imagine it ever gets stuck in infinite loops. But I admit I am too lazy to check against the interpreter. Also, complete failure is an exceptionally (heh) poor way of warning people about stuff. I hope that's not really it. -- Devin -- http://mail.python.org/mailman/listinfo/python-list
Re: how to tell a method is classmethod or static method or instance method
thank you. I know the second way works. but in my case, i need "method1" to be a class method, because I use it to create an object. I have a lot of classes that have "__init__" with 2 arguments -- self, and user id. usually, "SomeClass(user_id)" is used to create an object of "SomeClass", but if "SomeClass" has a class method named "method1", "method1" will be used to finish the job. and i get it. the context is useful. On 2012/02/14, at 18:52, Cameron Simpson wrote: > On 14Feb2012 13:13, Zheng Li wrote: > | > On 13Feb2012 15:59, Zheng Li wrote: > | > | how to tell a method is class method or static method or instance > method? > | > > | > Maybe a better question is: > | > under what circumstances do you need to figure this out? > | > | I can get "method1" of class "Test" by > | a = getattr(Test, "method1") > | > | and I also want know how to invoke it > | a() or a(Test()) > > Normally: > > a(T) > > where T is an object of type/class Test. So your second approach is > notionally correct (aside from making a throwaway object that is then > discarded). > > | BTW: > | I don't see what the problem is if I ask a question just because I am > curious about it. > > There's nothing wrong with it at all. > > But often, questions arise from some other circumstances and this one is > of such a flavour that if you wanted this code in a real application it > would _often_ be the wrong solution to seek, because normally you know > how to call something - it is not normally useful to introspect it to > decide what to do. > > So I was wondering what the outer context might be, because there may > well have been a better solution to the situation that brought up the > specific question. > > Simple curiosity is sufficient reason, of course. > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > Too young to rest on the weekend, too old to rest during the week. >- Mark Randol -- http://mail.python.org/mailman/listinfo/python-list
Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?
On 15/02/2012 01:43, Devin Jeanpierre wrote: On Tue, Feb 14, 2012 at 1:05 PM, MRAB wrote: And yeah, even something as crazy as ()* works, but as soon as it becomes (a*)* it doesn't work. Weird. I think it's a combination of warning the user about something that's pointless, as in the case of "$*", and producing a pattern which could cause the internal regex engine to get stuck in an infinite loop. Considering that ()* works fine, I can't imagine it ever gets stuck in infinite loops. But I admit I am too lazy to check against the interpreter. Also, complete failure is an exceptionally (heh) poor way of warning people about stuff. I hope that's not really it. There is one place in the re engine where it tries to avoid getting stuck in an infinite loop because of a zero-width match, but the fix inadvertently causes another bug. It's described in issue #1647489. -- http://mail.python.org/mailman/listinfo/python-list
TEST AN EXECUTABLE PYTHON SCRIPT SPEED UNDER A PYTHON SHELL
After my testing of JAVA, PYTHON, VB, C-sharp and Erlang like script languages, I noticed that script languages should be timed after the shell interpreter completed loaded. The start up loading time of script interpreters should be excluded in the measure of executing a byte code script. This also explains why C-executables are fast in manny testing programs of various languages to out beat all interpreter loading languages. But I computed the Euler'of s number for tens of thousands of digitsunder different shells , then I was able to check the speed issues of various computer languages. My question is whether a lot speed testings of computer languages are done in a biased way toward script languages to be slow? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. C++11
sturlamolden wrote: > >There are bigsimilarities between Python and the new C++ standard. Now >we can actually use our experience as Python programmers to write >fantastic C++ :-) This is more true than you might think. For quite a few years now, I've been able to do an almost line-for-line translation of my Python programs to C++ programs. (Microsoft has had a "for each" extension for a while that made this easier.) -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list