By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Some help with strings

P: 32
Hi,

I am just wondering if anyone can tell me how to do this :

Say I have a list like this :

listA = ['c','c','c','c','c','c']

and I want to print out the contents but I don't want to square brackets .... for example if I do :

print listA

I get ----> ['c','c','c','c','c','c']

But I just want this ------> 'c','c','c','c','c','c' to be saved as a string

Is this possible?

I didn't bother with CODE tags seeing as there is no real code here.

Thanks
Nov 25 '08 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
The answer is .... YES.
Expand|Select|Wrap|Line Numbers
  1. >>> listA = ['c','c','c','c','c','c']
  2. >>> ','.join(listA)
  3. 'c,c,c,c,c,c'
  4. >>> print ','.join([repr(item) for item in listA])
  5. 'c','c','c','c','c','c'
  6. >>> 
Nov 25 '08 #2

P: 32
Thanks ... that's it. Perfect.
Nov 25 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.