Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31493 > unrolled thread
| Started by | Anatoli Hristov <tolidtm@gmail.com> |
|---|---|
| First post | 2012-10-17 12:10 +0200 |
| Last post | 2012-10-17 18:46 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Index in a list Anatoli Hristov <tolidtm@gmail.com> - 2012-10-17 12:10 +0200
Re: Index in a list Hans Mulder <hansmu@xs4all.nl> - 2012-10-17 18:46 +0200
| From | Anatoli Hristov <tolidtm@gmail.com> |
|---|---|
| Date | 2012-10-17 12:10 +0200 |
| Subject | Index in a list |
| Message-ID | <mailman.2338.1350468659.27098.python-list@python.org> |
Hello,
I'm trying to index a text in a list as I'm importing a log file and
each line is a list.
What I'm trying to do is find the right line which contains the text
User : and take the username right after the text "User :", but the
list.index("(User :") is indexing only if all the text matching. How
can I have the right position of the line which contains the word
("(User :")
Thanks
Anatoli
[toc] | [next] | [standalone]
| From | Hans Mulder <hansmu@xs4all.nl> |
|---|---|
| Date | 2012-10-17 18:46 +0200 |
| Message-ID | <507ee0e4$0$6934$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #31493 |
On 17/10/12 12:10:56, Anatoli Hristov wrote:
> I'm trying to index a text in a list as I'm importing a log file and
> each line is a list.
>
> What I'm trying to do is find the right line which contains the text
> User : and take the username right after the text "User :", but the
> list.index("(User :") is indexing only if all the text matching. How
> can I have the right position of the line which contains the word
> ("(User :")
Perhaps something like:
target = "(User :"
for line in your_list:
position = line.find(target)
if position >= 0:
print line[position+len(target):]
Hope this helps,
-- HansM
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web