Derek Basch wrote:
> Interesting stuff Andrew. I do generally avoid string concantination
> for the reason listed in the Python Performance Tips but your analysis
> kinda puts that in question.
Thanks.
It was interesting for me to. I hadn't looked at the implementation
for string % before and wa
"runes" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> [Andrew Dalke]
>> I therefore disagree with the idea that simple
>> string concatenation is always to be eschewed
>> over string interpolation.
String cat (+) is fine for joining a few short strings.
> Andrew, what you writ
Interesting stuff Andrew. I do generally avoid string concantination
for the reason listed in the Python Performance Tips but your analysis
kinda puts that in question. Such a dense discussion for me just trying
to find the enumerate() function :). I guess that is why the python
list is so great. Y
[Andrew Dalke]
> I therefore disagree with the idea that simple
> string concatenation is always to be eschewed
> over string interpolation.
Andrew, what you write makes sense. I've never really tested it, just
read it several places, fx here:
http://www.python.org/moin/PythonSpeed/PerformanceTip
Andrew Dalke wrote:
"pet#%i" % (i+1)
(NOTE: most times that's written %d instead of %i)
Any reason to prefer %d over %i? The library reference seems to suggest
that they're the same thing[1]. I've typically used %i since I can
remember it from the int type, like I can remember %f from the floa
runes wrote:
> You should avoid the "a" + "b" + "c" -kind of concatenation. As strings
> at immutable in Python you actually makes copies all the time and it's
> slow!
The OP wrote
print "pet" + "#" + num_pets
(properly str(num_pets) )
You recommended the "alternative used in Steven Bethard
You should avoid the "a" + "b" + "c" -kind of concatenation. As strings
at immutable in Python you actually makes copies all the time and it's
slow!
The alternative used in Steven Bethard's example is preferable.
--
http://mail.python.org/mailman/listinfo/python-list
Derek Basch wrote:
> ooops you are right. Should have been:
>
> pets = ["cat", "dog", "bird"]
> num_pets = 0
> for i in pets:
>num_pets += 1
>print "pet" + "#" + num_pets
Traceback (most recent call last):
File "example.py", line 5, in ?
print "pet" + "#" + num_pets
TypeError: canno
ooops you are right. Should have been:
pets = ["cat", "dog", "bird"]
num_pets = 0
for i in pets:
num_pets += 1
print "pet" + "#" + num_pets
That's the problem with one offs. I don't read them :).
--
http://mail.python.org/mailman/listinfo/python-list
Derek Basch wrote:
Is there a better way to count iterations that this?:
pets = 0
for i in pets:
pets += 1
print "pet" + "#" + pets
You can use 'enumerate' to get the index, but the code above wont work -
you are trying to iterate over a non-sequence.
Will McGugan
--
"".join( [ {'@':'@','
Derek Basch wrote:
Is there a better way to count iterations that this?:
pets = 0
for i in pets:
pets += 1
print "pet" + "#" + pets
for i, pet in enumerate(pets):
print 'pet#%i' % (i + 1)
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Is there a better way to count iterations that this?:
pets = 0
for i in pets:
pets += 1
print "pet" + "#" + pets
Thanks,
Derek Basch
--
http://mail.python.org/mailman/listinfo/python-list
12 matches
Mail list logo