Just a quick one

Ian J Cottee ian at cottee.org
Thu Aug 26 07:24:52 CEST 2004

M. Clift wrote:

> At the risk of looking stupid would someone mind showing me how this is done
> in this case. I can't remove the brackets from (('Bob', 'Mary'), ('Spam',
> 'chips'))  to give(('Bob', 'Mary', 'Spam', 'chips')) . From what Phil and Sm
> said I thought it would be easy. I've tried using list( ). I've had a go at
> referencing the individual elements...

Noodle around with IDLE (if using windows it should be in your python 
group). It's a great way to play with this stuff.

	>>> stuff = (('Bob', 'Mary'), ('Spam', 'chips'))

Hmmm - what is stuff?

	>>> type(stuff)
	<type 'tuple'>

I see. How big is it?

	>>> len(stuff)

Ah ... so ...

	>>> stuff[0]
	('Bob', 'Mary')
	>>> stuff[1]
	('Spam', 'chips')

So in that case

	>>> morestuff = stuff[0]+stuff[1]
	>>> morestuff
	('Bob', 'Mary', 'Spam', 'chips')
	>>> type(morestuff)
	<type 'tuple'>
	>>> evenmorestuff = list(morestuff)
	>>> evenmorestuff
	['Bob', 'Mary', 'Spam', 'chips']
	>>> type(evenmorestuff)
	<type 'list'>

Well - it got rid of your brackets. But was it what you wanted? Maybe 
you actually now want.

	>>> stringstuff = ', '.join(morestuff)
	>>> stringstuff
	'Bob, Mary, Spam, chips'
	>>> type(stringstuff)
	<type 'str'>

Hmmm - getting quite stuff'y in here isn't it? :)


More information about the Python-list mailing list