Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

splitting and concatenating a string

I was wondering if python had a built in function similar to

string->list

and list->string in scheme.

So for example I would like to turn 'abc' into ['a','b','c'] and vice versa using a built in function.

like image 751
LostLin Avatar asked Jul 17 '11 20:07

LostLin


People also ask

What is concatenating a string?

Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs.

How do you split a string into concatenate in Python?

Summary. Use the Python String split() method to split a string into a list of substrings. Use the sep argument to specify where the split should occur. Use the maxsplit argument to limit the number of splits.

What are the 2 methods used for string concatenation?

There are two ways to concatenate strings in Java: By + (String concatenation) operator. By concat() method.


1 Answers

String to list:

>>> list('abc')
['a', 'b', 'c']

List to string:

>>> ''.join(['a', 'b', 'c'])
'abc'
like image 176
Tugrul Ates Avatar answered Oct 21 '22 05:10

Tugrul Ates