473,385 Members | 2,069 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.

How to convert this list to string?

Hi all

I have a list like:
>>list
[1, 2, 3]
>>list[1:]
[2, 3]

I want to get a string "2 3"
>>str(list[1:])
'[2, 3]'

How can I do that ?

thanks

Oct 18 '06 #1
5 2469
On 18 Oct 2006 00:20:50 -0700, Jia Lu <Ro*****@gmail.comwrote:
I want to get a string "2 3"
>str(list[1:])
'[2, 3]'

How can I do that ?
' '.join(str(i) for i in list[1:])

-- Theerasak
Oct 18 '06 #2
Jia Lu wrote:
Hi all

I have a list like:
>>>list
[1, 2, 3]
>>>list[1:]
[2, 3]

I want to get a string "2 3"
>>>str(list[1:])
'[2, 3]'

How can I do that ?
" ".join(str(x) for x in list)
-Travis

Oct 18 '06 #3
Jia Lu wrote:
Hi all

I have a list like:
>>>list
[1, 2, 3]
>>>list[1:]
[2, 3]

I want to get a string "2 3"
>>>str(list[1:])
'[2, 3]'

How can I do that ?
http://effbot.org/zone/python-list.htm#printing

</F>

Oct 18 '06 #4
Jia Lu wrote:
Hi all

I have a list like:
>>>list
[1, 2, 3]
>>>list[1:]
[2, 3]

I want to get a string "2 3"
>>>str(list[1:])
'[2, 3]'

How can I do that ?

thanks
Just to be different from the other suggestions...
>>a = [1, 2, 3]
str(a[1:]).strip('[]').replace(',', '')
'2 3'

By the way. It's a good idea to try not to use 'list' or other built-in names
for your own objects. Best to start with good habits so that you avoid odd hard
to find bugs later.

Cheers,
Ron
Oct 18 '06 #5
Thank you very much. I memoed all you views.

:)

Oct 18 '06 #6

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

Similar topics

7
by: Klaus Neuner | last post by:
Hello, I need a function that converts a list into a set of regexes. Like so: string_list = print string_list2regexes(string_list) This should return something like:
5
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: Steve | last post by:
I have a very simple datatable of 1 column which I retrieve from a database, call it 'data'. Dim data As Data.DataTable data = myobject.mymethod(parameter) I want to now turn this 'data' into...
23
by: comp.lang.tcl | last post by:
I have a TCL proc that needs to convert what might be a list into a string to read consider this: ]; # OUTPUTS Hello World which is fine for PHP ]; # OUTPUT {{-Hello}} World, which PHP...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
2
by: CodeMonkey775 | last post by:
I'm having problems passing a variable to a method which is executed and compiled using CodeDom. The situation is I have a List<CellData> with cells, each containing a formula (like Excel). I am...
1
by: pnbaocuong | last post by:
Dear All When I try to use convert function of MS sql server like this: String sql = " (employee_id = '" + employee_id + "') and ((convert(VARCHAR,w_date,103) = '" + w_date + "'))"; ...
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.