开发者

Splitting strings using a delimiter in python [closed]

开发者_开发问答 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

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?


So, your input is 'dan|warrior|54' and you want "warrior". You do this like so:

>>> dan = 'dan|warrior|54'
>>> dan.split('|')[1]
"warrior"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜