Re: [Tutor] understanding join

2008-07-30 Thread Alan Gauld
"Steve Poe" <[EMAIL PROTECTED]> wrote Your explanation is very help. It does make be wonder the usefulness of join with strings. Do you have a practical example/situation? Its not really intended for strings but it needs to work that way to be consistent because strings are just another type

Re: [Tutor] understanding join

2008-07-30 Thread Alan Gauld
"Steve Poe" <[EMAIL PROTECTED]> wrote In [3]: people = [ 'Tom', 'Dick', 'Harry' ] Okay, now let's join people to people and what do we get? An error, join only works on a single string. It joins the elements of a sequence of strings into a single string using the 'owning' string. In some w

Re: [Tutor] understanding join

2008-07-30 Thread John Fouhy
On 31/07/2008, Steve Poe <[EMAIL PROTECTED]> wrote: > Your explanation is very help. It does make be wonder the usefulness > of join with strings. Do you have a practical example/situation? Kent's example is common: you might have a list of strings that you want to display to the user, so you ca

Re: [Tutor] understanding join

2008-07-30 Thread Steve Poe
Say I have a sequence seq and a string s, and I call s.join(seq). Here's what it does: s.join(seq) == seq[0] + s + seq[1] + s + seq[2] + s + ... + seq[-2] + s + seq[-1] So if you call 'abc'.join('ABC'), you get: 'ABC'[0] + 'abc' + 'ABC'[1] + 'abc' + 'ABC'[2] which is: 'A' + 'abc' + 'B'

Re: [Tutor] understanding join

2008-07-30 Thread Steve Poe
Does this look useful? In [3]: people = [ 'Tom', 'Dick', 'Harry' ] In [4]: ', '.join(people) Out[4]: 'Tom, Dick, Harry' Your confusion is in thinking about the string 'ABC' as a single entity. For the purposes of join(), it is a sequence of three letters. The argument to join() is a sequence of

Re: [Tutor] understanding join

2008-07-30 Thread Kent Johnson
> On 31/07/2008, Steve Poe <[EMAIL PROTECTED]> wrote: >> Okay, I can see the order of the join is the same as mine, but >> the join still seems to be out of sequence. I am thinking it should be >> 'abcABC' or 'ABCabc' not at the beginning, middle, and end of the >> original string. At least, I

Re: [Tutor] understanding join

2008-07-30 Thread John Fouhy
On 31/07/2008, Steve Poe <[EMAIL PROTECTED]> wrote: > Good point. I guess I am surprised a little that Python does not error > on that you cannot assign a variable to a module name. I know I need > to learn proper coding techniques. Well, that wouldn't really work because you don't know what o

Re: [Tutor] understanding join

2008-07-30 Thread John Fouhy
On 31/07/2008, Steve Poe <[EMAIL PROTECTED]> wrote: > Hi tutor list, > > Just trying to add some clarity to the built-in function strings using > join. The Python help > screen says it returns a string which is a concatenation of strings in > sequence. I am concatenating > the string I am workin