Skip to main content

Posts

Showing posts from October, 2015

Python: Convert List to String

The method keyword is similar like in JavaScript. Both are using the join keyword. But in Python, the syntax is reversed (or not, depends on your perspective). JavaScript inputArray.join(separator) For example: var inputArray = [1, 2, 3, 4, "tro", "lo", "lo"]; console.log(inputArray.join(" ")); // console output will yield: "1 2 3 4 tro lo lo" (string) In the example above, the array input is converted to strings output with one horizontal white space as the separator . Python separator.join(inputList) For example: inputList = ["dark", "wing", "duck"] outputString = " ".join(inputList) # outputString variable consists of: "dark wing duck" In the example above, the list input is converted to strings output also with one horizontal white space as the separator . Unlike in JavaScript, which we can convert an array with nonuniform items to string, the join() method ...
Monkey Raptor uses cookies or biscuits 🍪 for analytics, functionality, and advertisements. More info in Privacy Policy