|
||||||
| Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||||
|
I have been playing around with Python lately, and there is one operation that I have yet to figure out how to do. This is splitting a string into its individual characters, which I used to be able to do with other languages by simply splitting with an empty separator. In python, however, this returns an error.
Code:
>>> "testing123".split("")
Traceback (most recent call last):
File "<pyshell#14>", line 1, in ?
"testing123".split("")
ValueError: empty separator
__________________
http://www.mattnichols.net |
| Sponsored Links |
|
|
|
|||||
|
I don't remember if there's such function (I'm a bit rusty), but it can be done in two lines, using a for-loop.
This shows how, using the interpreter: Code:
>>> the_string = "Hello, World!" >>> the_list = [] >>> for each_character in the_string: the_list.append(each_character) >>> the_list ['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'] >>>
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum C/C++ resources - C/C++ frequently asked questions Python resources - Python frequently asked questions I'm always up for a chat, so feel free to contact me... |
|
|||||
|
Great, that works just fine. Thanks.
__________________
http://www.mattnichols.net |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strings | clookid | PHP Tutorials | 2 | 01-13-2007 03:23 PM |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| gaylo565 | ........ | 18.00000 |
| WingedPanther | ........ | 15.00000 |
| |pH| | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 66%