Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jinja2 Split string by white spaces

I'm using Jinja2 template engine (+pelican).

I have a string saying "a 1", and I am looking for a way to split that string in two by using the white-space as the delimiter.

So the end result I'm looking for is a variable which holds the two values in a form of an array. e.g. str[0] evaluates to "a" & str[1] evaluates to "1".

Thanks in advance.

like image 316
elad.chen Avatar asked Dec 19 '13 09:12

elad.chen


1 Answers

Calling split on the string should do the trick:

"a 1".split()
like image 120
Jakub Kotowski Avatar answered Oct 15 '22 12:10

Jakub Kotowski