Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107058

RE: How to print a part of a string?

From Dan Strohl <D.Strohl@F5.com>
Newsgroups comp.lang.python
Subject RE: How to print a part of a string?
Date 2016-04-15 14:27 +0000
Message-ID <mailman.26.1460730463.6324.python-list@python.org> (permalink)
References <edfe7d06-e8b1-4cef-92c3-2d1a217ebdac@googlegroups.com> <edbd324de7cb45eab05432ccbe2aa0c3@seaexchmbx03.olympus.F5Net.com>

Show all headers | View raw


As with lots of things in python, there are lots of ways of approaching this, here are some hints for you to think about (in no particular order):

- REGEX 
- replace()
- string[:y]
- split()

And of course, you could consider creating a table with every possible string that could start with "ABC", and it's matching non-"ABC" string, then lookup the string in the table and get your match, it's a bit brute forcey, but it would work (eventually) <grin>

Good luck in your homework!

Dan




> -----Original Message-----
> From: Python-list [mailto:python-list-bounces+d.strohl=f5.com@python.org]
> On Behalf Of durgadevi1
> Sent: Friday, April 15, 2016 5:13 AM
> To: python-list@python.org
> Subject: How to print a part of a string?
> 
> Hello all,
> 
> I have another homework problem.
> 
> I have a textfile. It contains lines of string.
> 
> I am required to only print out a certain part of the string.
> 
> For example the textfile contain:
> 
> ABC XXXXX NNNNN
> BCD QQQQQ EEEEE
> ABC WWWWW AAAAA
> 
> 
> I need to print all the parts that come after only ABC.
> 
> That means I need to print only XXXXX from the first line and WWWWW from
> the second line.
> 
> I'm not sure of what code to use to achieve that.
> --
> https://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to print a part of a string? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-15 05:13 -0700
  Re: How to print a part of a string? Joel Goldstick <joel.goldstick@gmail.com> - 2016-04-15 08:28 -0400
  RE: How to print a part of a string? Dan Strohl <D.Strohl@F5.com> - 2016-04-15 14:27 +0000
  Re: How to print a part of a string? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-16 00:25 -0700
  RE: How to print a part of a string? Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-15 12:40 +0000

csiph-web