I have a file that contains some information in the line. I just want to print the words after the last character ∑.
How can I do this?
text:
App∑Category∑Rating∑Reviews∑Size∑Installs∑Type∑Price∑Content Rating∑Genres∑Last Updated∑Current Ver∑Android Ver
Photo Editor & Candy Camera & Grid & ScrapBook∑ART_AND_DESIGN∑4.1∑159∑19M∑10,000+∑Free∑0∑Everyone∑Art & Design∑7-Jan-18∑1.0.0∑4.0.3 and up
Coloring book moana∑ART_AND_DESIGN∑3.9∑967∑14M∑500,000+∑Free∑0∑Everyone∑Art & Design;Pretend Play∑15-Jan-18∑2.0.0∑4.0.3 and up
Code:
def mapper(_, line):
words = line.split('∑')
Result:
[4.0.3 and up, 4.0.3 and up]
>Solution :
An efficient method is to use rsplit with a maxsplit of 1, and take the last item:
def mapper(_, line):
last = line.rsplit('∑', maxsplit=1)[-1]
Note that this will default to the full line if there isn’t the split character in the line.
If you want to ensure that there is a valid split:
def mapper(_, line):
chunks = line.rsplit('∑', maxsplit=1)
last = chunks[1] if len(chunks)==2 else None # or other default value