Splitting strings using a delimiter in python.

Posted by Jahkr on Stack Overflow See other posts from Stack Overflow or by Jahkr
Published on 2011-01-17T19:37:43Z Indexed on 2011/01/17 19:54 UTC
Read the original article Hit count: 548

Filed under:

OK so I have a string that has this:

Dan|warrior|54

I'm trying to make so I can use python and split it using | as the delimiter. Here's what I have so far:

#!/usr/bin/env python
dan = 'dan|warrior|54'
print dan.split('|')

and that results into this:

['dan', 'warrior', '54']

I know it's incomplete but what do I have to do to finish it? Yes, I tried googling this problem... but it's not happening. :(

I want so that I can choose specifically which one from the delimiter so if I was dan.split('|')[1] .. it would pick warrior. See my point?

© Stack Overflow or respective owner

Related posts about python