Oops: difference in operation of string.join and ''.join 
Author Message
 Oops: difference in operation of string.join and ''.join

    >>> ''.join([x+y for x, y in zip('test', 'dust')])
    'tdeusstt'
    >>> import string
    >>> string.join([x+y for x, y in zip('test', 'dust')])
    'td eu ss tt'

    John> What is this?

The default separator for string.join is a single space.  Use

    string.join([x+y for x, y in zip('test', 'dust')], '')

instead.

--

http://www.*-*-*.com/
http://www.*-*-*.com/



Fri, 09 Apr 2004 04:42:42 GMT  
 Oops: difference in operation of string.join and ''.join

Quote:
>>> ''.join([x+y for x, y in zip('test', 'dust')])
'tdeusstt'
>>> import string
>>> string.join([x+y for x, y in zip('test', 'dust')])

'td eu ss tt'

What is this?



Fri, 09 Apr 2004 03:40:36 GMT  
 Oops: difference in operation of string.join and ''.join

Quote:

> >>> ''.join([x+y for x, y in zip('test', 'dust')])
> 'tdeusstt'
> >>> import string
> >>> string.join([x+y for x, y in zip('test', 'dust')])
> 'td eu ss tt'

> What is this?

That's because they're not equivalent.  string.join and ' '.join would
be, though.

--

 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Scars are like memories.  We do not have them removed.
\__/ Chmeee
    Maths reference / http://www.alcyone.com/max/reference/maths/
 A mathematics reference.



Fri, 09 Apr 2004 05:13:30 GMT  
 Oops: difference in operation of string.join and ''.join
You need to designate what to join with:

string.join([x+y for x, y in zip('test', 'dust')],'')

--

Emile van Sebille

---------

Quote:

> >>> ''.join([x+y for x, y in zip('test', 'dust')])
> 'tdeusstt'
> >>> import string
> >>> string.join([x+y for x, y in zip('test', 'dust')])
> 'td eu ss tt'

> What is this?



Fri, 09 Apr 2004 06:51:08 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. better way to say 'recursive join'

2. Problem with 'file join' command

3. bug in 'file join'

4. Join Network World's on-line Java debate

5. Join PSSI's smalltalk development team

6. Join PSSI's smalltalk team

7. Art and all that Jazz: nowadays, doses join against stupid rains, unless they're rich

8. Thread#join doesn't accept a timeout?

9. RFC: File.join removing redundant /'s

10. Join PSSI's development team - VisualAge Smalltalk

11. Join PSSI's dynamic smalltalk team!

12. Join Performance Software's Dynamic Smalltalk Team..........

 

 
Powered by phpBB® Forum Software