Re: [Tutor] Pythonic way

2018-11-21 Thread Alan Gauld via Tutor
On 20/11/2018 22:35, Steven D'Aprano wrote: > On Tue, Nov 20, 2018 at 08:22:01PM +, Alan Gauld via Tutor wrote: > >> I think that's a very deliberate feature of Python going back >> to its original purpose of being a teaching language that >> can be used beyond the classroom. > > I don't

Re: [Tutor] Pythonic way

2018-11-20 Thread Steven D'Aprano
On Tue, Nov 20, 2018 at 08:22:01PM +, Alan Gauld via Tutor wrote: > I think that's a very deliberate feature of Python going back > to its original purpose of being a teaching language that > can be used beyond the classroom. I don't think that is correct -- everything I've read is that

Re: [Tutor] Pythonic way

2018-11-20 Thread Mark Lawrence
On 20/11/2018 18:08, Avi Gross wrote: We have two completely separate ways to format strings that end up with fairly similar functionality. Actually, there is an implicit third way  You could argue five ways :-) 1. C printf style formatting

Re: [Tutor] Pythonic way

2018-11-20 Thread Alan Gauld via Tutor
On 20/11/2018 18:08, Avi Gross wrote: > ... So there isn’t really ONE pythonic way for many things. That's true and, I think, inevitable for anything developed in the open source world. If you compare it to a language entirely controlled by a single mind - like Oberon or Eiffel say - then there

[Tutor] Pythonic way

2018-11-20 Thread Avi Gross
This is not a question or reply. Nor is it short. If not interested, feel free to delete. It is an observation based on recent experiences. We have had quite a few messages that pointed out how some people approach solving a problem using subconscious paradigms inherited from their

[Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread spawgi
Hello, My code is - l = len(m) item = str(m[1]) for i in range(2,l): item = item + - + str(m[i]) This code is part of a bigger function. It works fine. But I am not happy with the way I have written it. I think there is a better (Pythonic) way to rewrite it. If anyone knows how to improve

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread Steven D'Aprano
spa...@gmail.com wrote: Hello, My code is - l = len(m) item = str(m[1]) for i in range(2,l): item = item + - + str(m[i]) This code is part of a bigger function. It works fine. But I am not happy with the way I have written it. I think there is a better (Pythonic) way to rewrite it. If

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread spawgi
Hello Steven, Thanks a lot for the detailed answer. I will implement your suggestions. Really appreciate it. Thanks and Regards, Sumod On Fri, Jan 27, 2012 at 4:34 AM, Steven D'Aprano st...@pearwood.infowrote: spa...@gmail.com wrote: Hello, My code is - l = len(m) item = str(m[1]) for

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread Andre' Walker-Loud
Hi Steven, (5) When assembling strings from substrings, never use repeated concatenation using + as that can be EXTREMELY slow. Use str.join to build the string in one assignment, instead of multiple assignments. Your code shown above is *very* inefficient and will be PAINFULLY slow if m

Re: [Tutor] Pythonic way to normalize vertical whitespace

2009-05-09 Thread spir
Le Fri, 08 May 2009 13:03:47 -0400, pyt...@bdurham.com s'exprima ainsi: [...] Approaches: 1. split text to list of lines that get stripped then: a. walk this list building a new list of lines that track and ignore extra blank lines -OR- b. re-join lines and replace '\n\n\n' wth' \n\n' until

[Tutor] Pythonic way to normalize vertical whitespace

2009-05-08 Thread python
Note: Following cross-posted to python-list where it got queued due to suspicious subject line. I'm looking for suggestions on technique (not necessarily code) about the most pythonic way to normalize vertical whitespace in blocks of text so that there is never more than 1 blank line between

Re: [Tutor] Pythonic way to normalize vertical whitespace

2009-05-08 Thread bob gailer
pyt...@bdurham.com wrote: Note: Following cross-posted to python-list where it got queued due to suspicious subject line. I'm looking for suggestions on technique (not necessarily code) about the most pythonic way to normalize vertical whitespace in blocks of text so that there is never more

Re: [Tutor] Pythonic way to normalize vertical whitespace

2009-05-08 Thread Kent Johnson
On Fri, May 8, 2009 at 1:03 PM, pyt...@bdurham.com wrote: Note: Following cross-posted to python-list where it got queued due to suspicious subject line. I'm looking for suggestions on technique (not necessarily code) about the most pythonic way to normalize vertical whitespace in blocks of

[Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Malcolm Greene
Suggestions on the best way to extract delimited substrings strings from a larger string? Background: I have a long multi-line string with expressions delimited with '(' and ')' markers. I would like to extract these substrings and process them in a loop. Because the left and right delimiters

Re: [Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Kent Johnson
Malcolm Greene wrote: Suggestions on the best way to extract delimited substrings strings from a larger string? Background: I have a long multi-line string with expressions delimited with '(' and ')' markers. I would like to extract these substrings and process them in a loop. What

Re: [Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Alan Gauld
Malcolm Greene [EMAIL PROTECTED] wrote in Background: I have a long multi-line string with expressions delimited with '(' and ')' markers. I would like to extract these substrings and process them in a loop. I know how to do this task with regular expressions, but I'm always cautious

[Tutor] Pythonic way to try a few times, then raise exception?

2007-10-26 Thread Allen Fowler
Hello, I have a block of code buried deep in a module that I expect to fail periodically. (Calls to other machines over slow network, and such.) Generally, though, trying it a second / third will work. Is there clean way to write this on Python? Thanks

Re: [Tutor] Pythonic way to try a few times, then raise exception?

2007-10-26 Thread Alan Gauld
Allen Fowler [EMAIL PROTECTED] wrote I have a block of code buried deep in a module that I expect to fail periodically. (Calls to other machines over slow network, and such.) Generally, though, trying it a second / third will work. Is there clean way to write this on Python? There

Re: [Tutor] Pythonic way to try a few times, then raise exception?

2007-10-26 Thread johnf
On Friday 26 October 2007 03:17:47 pm Alan Gauld wrote: Allen Fowler [EMAIL PROTECTED] wrote I have a block of code buried deep in a module that I expect to fail periodically. (Calls to other machines over slow network, and such.) Generally, though, trying it a second / third will