On Thu, May 30, 2013 at 3:16 PM, Steven D'Aprano wrote:
>
> Sure enough, ''.join(list-of-substrings) is measurably faster than
> ''.join(iterator-of-substrings).
A tuple or list is used directly. Otherwise join() has to create an
iterator and build a new list.
This isn't directly related to the
On Thu, May 30, 2013 at 6:35 PM, Oscar Benjamin
wrote:
>
> It's also for BINARY_ADD in the form a = a + b:
Right you are. It sees that the next operation is a store back to "a".
It wouldn't work the other way around, i.e. a = b + a.
___
Tutor maillist
On 30 May 2013 21:35, eryksun wrote:
> In terms of sequence methods, it's inplace concatenation. On their
> own, immutable string types only support regular concatenation, but
> the interpreter can evaluate the concatenation inplace for special
> cases. Specifically, it can resize the target strin
On Wed, May 29, 2013 at 12:51 PM, boB Stepp wrote:
> On Wed, May 29, 2013 at 11:07 AM, Oscar Benjamin
> wrote:
>
>> I don't know exactly how str.join is implemented but it does not use
>> this quadratic algorithm. For example if str.join would first compute
>> the length of the resulting string f
On 30/05/13 02:51, boB Stepp wrote:
On Wed, May 29, 2013 at 11:07 AM, Oscar Benjamin
wrote:
I don't know exactly how str.join is implemented but it does not use
this quadratic algorithm. For example if str.join would first compute
the length of the resulting string first then it can allocate
Sending again to the list (sorry boB)...
On 29 May 2013 17:51, boB Stepp wrote:
>> I don't know exactly how str.join is implemented but it does not use
>> this quadratic algorithm. For example if str.join would first compute
>> the length of the resulting string first then it can allocate memory
On Wed, May 29, 2013 at 11:07 AM, Oscar Benjamin
wrote:
> On 29 May 2013 16:38, boB Stepp wrote:
>> On Tue, May 28, 2013 at 9:34 PM, Steven D'Aprano wrote:
>>>
>>> However, a word of warning: although you *can* assemble a new string
>>> character by character like that, you should not, because
On 29 May 2013 16:38, boB Stepp wrote:
> On Tue, May 28, 2013 at 9:34 PM, Steven D'Aprano wrote:
>>
>> However, a word of warning: although you *can* assemble a new string
>> character by character like that, you should not, because it risks being
>> very slow. *Painfully* slow. If you want to
On Tue, May 28, 2013 at 9:34 PM, Steven D'Aprano wrote:
>
> On 28/05/13 13:54, Tim Hanson wrote:
>>
>
> However, a word of warning: although you *can* assemble a new string
> character by character like that, you should not, because it risks being very
> slow. *Painfully* slow. If you want to h
On 28 May 2013 22:33, Andreas Perstinger wrote:
> Wow, that means I can do this: print ''.join('But this parrot is dead!')
>>
>
> But why do you want to do that?
>
Actually, I meant to do this:
print ''.join(' '.join('But this parrot is dead'.split()))
Which has the same effect.
There is a
On 29.05.2013 05:20, Jim Mooney wrote:
On 28 May 2013 19:34, Steven D'Aprano wrote:
The standard method for assembling a string from a collection
of substrings is to do it in one go, using the join method,
Wow, that means I can do this: print ''.join('But this parrot is dead!')
But why
On 28 May 2013 19:34, Steven D'Aprano wrote:
The standard method for assembling a string from a collection
> of substrings is to do it in one go, using the join method,
Wow, that means I can do this: print ''.join('But this parrot is dead!')
--
Jim
Ornhgvshy vf orggre guna htyl
On 28/05/13 13:54, Tim Hanson wrote:
Okay, so I made it to FOR loops in the Lutz book. A couple of days ago I was
helped here with the .join method for creating strings from lists or tuples of
strings. I got to wondering if I could just, for the sake of learning, do the
same thing in a FOR loop
On 28/05/13 04:54, Tim Hanson wrote:
x=0; ham=''; b=['s','p','a','m'] #or, b=('s','p','a','m')
for t in b:
ham=ham+b[x]
print(ham);x+=1
Alright, it works, eventually. Can someone help me find a little more elegant
way of doing this? I'm sure there are several.
Python 'for
Some other tools, if you haven't come across them yet.
You already know about str.join ()
Slicing
>>>b=['s','p','a','m']
b [ : 1 ]
['s']
b [ : 2 ]
['s', 'p']
Also, consider
>>>len ( b)
4
>>>range ( 4 )
[ 0, 1, 2, 3, 4]
# which I can iterate over.
On Tue, May 28, 2013 at 4:54 AM, T
One way I can suggest is
x=0; ham=''; b=['s','p','a','m'] #or, b=('s','p','a','m')
> for t in b:
> ham=ham+b[x]
> print(ham);x+=1
>
>
> 't' is actually equal to b[x] and its faster then indexed based look-up.
so you can rewrite
ham = ham + b[x]
as
ham += t
and remove the x inc
Okay, so I made it to FOR loops in the Lutz book. A couple of days ago I was
helped here with the .join method for creating strings from lists or tuples of
strings. I got to wondering if I could just, for the sake of learning, do the
same thing in a FOR loop, since that's today's chapter:
x=0
17 matches
Mail list logo