473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Converting a List into a String

I have a List

list = ['f', 'e', 'd', 'c', 'b', 'a']

How can i convert it into a string so the output is

fedcba

i used

for a in list:
print a,

the output is

f e d c b a

How can i remove the spaces b/w each letter?
--
* Posted with NewsLeecher v3.0 Beta 7
* http://www.newsleecher.com/?usenet
Nov 5 '05 #1
3 82890
''.join['h','i']

bl**@blah.blah wrote:
I have a List

list = ['f', 'e', 'd', 'c', 'b', 'a']

How can i convert it into a string so the output is

fedcba

i used

for a in list:
print a,

the output is

f e d c b a

How can i remove the spaces b/w each letter?
--
* Posted with NewsLeecher v3.0 Beta 7
* http://www.newsleecher.com/?usenet


Nov 5 '05 #2
bl**@blah.blah wrote:
I have a List

list = ['f', 'e', 'd', 'c', 'b', 'a']

How can i convert it into a string so the output is

fedcba

i used

for a in list:
print a,

the output is

f e d c b a

How can i remove the spaces b/w each letter?


print "".join(list)

BTW list isnt a good name for a list, it hides the built in type.
Will McGugan
--
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in
"jvyy*jvyyzpthtna^pbz")
Nov 5 '05 #3
bl**@blah.blah wrote:
list = ['f', 'e', 'd', 'c', 'b', 'a']

How can i convert it into a string so the output is

fedcba


print ''.join(list)
Nov 5 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ajay | last post by:
hi! how do i go about converting a Python object or tuple to a string. i am currently doing import cPickle as pickle str = pickle.dumps(obj) is thate efficient? is that the best way to do...
4
by: blrmaani | last post by:
Here is what I want: string s1 = "This is a list of string"; list<string> s2 = s1.some_method(); Now, I should be able to traverse list s2 and get each member ( which is of type 'string' ). ...
3
by: news1.sympatico.ca | last post by:
I have a single column list in the following format: John Smith 123 Anystreet Anytown, state zip Tel: 333-555-1212 Fax: 333-555-2121 Dave Jones 321 Main Street
2
by: Richy | last post by:
Hi, I have a class that exposes the Microsoft.DirectX.Direct3D.Compare property, which allows a drop-down list of values (such as Never, Always etc) to be selected via the propertygrid. I write...
1
by: Kevin S Gallagher | last post by:
I found this code (pretty sure it was from a MVP) for converting a string variable to a form object which works fine within a form. Take the code and place it into a code module and it fails on the...
0
by: rrp83 | last post by:
Hi All Can anyone fwd me the code for converting a string to bytes similar to the GetBytes function in C# and viceversa?? Regards, RRP83
2
by: CoreyWhite | last post by:
Problem: You have numbers in string format, but you need to convert them to a numeric type, such as an int or float. Solution: You can do this with the standard library functions. The...
12
by: Samir | last post by:
Hi Everyone, I am relatively new to Python so please forgive me for what seems like a basic question. Assume that I have a list, a, composed of nested lists with string representations of...
6
by: gsBytes | last post by:
I am working with a specialized graph class, which has a node class and an edge class. In the node class, there is a list of pointers to each edge. Code that uses the graph must be able to see what...
1
by: dhivya m | last post by:
In python I need to get the input from stdin and then convert the list to a string.I tried with rstrip but it is not working with list. Can anyone suggest someway to solve this.. Thank you..
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.