free hit counter

Python Split and List

Split

One of the most useful string operations in Python is split.

If we wanted to split "Free as in Freedom" into an array of words we would do.

array = "Free as in Freedom".split(" ")  

We can pass any character(s) as an argument

array = "FreexasxinxFreedom".split("x")  

Both would render the same array.

But how do we split a string into letters? With list.
List

List allows you to take a string or some other gathering of items (ints, arrays, etc) and split them into their individual items in an array. This is mostly used with strings.

list("DigitalOcean rules")  

This would split every character (including spaces) into an array.