67% found this document useful (3 votes)
5K views2 pages

Zenpython Handson1

This document contains code snippets for processing text data. It reads lines from a file, strips whitespace, and extracts portions based on delimiter patterns. It also defines a function to substitute strings in a list of addresses based on a regular expression pattern.

Uploaded by

Senthil Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
5K views2 pages

Zenpython Handson1

This document contains code snippets for processing text data. It reads lines from a file, strips whitespace, and extracts portions based on delimiter patterns. It also defines a function to substitute strings in a list of addresses based on a regular expression pattern.

Uploaded by

Senthil Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

========================================================================

PDH Try1
========================================================================
=====================================
fp = io.StringIO(zenPython)
return(fp)
======================
import sys
import os
import io
lst = list()
fp = io.StringIO(zenPython)
zenlines = fp.readlines()
zenlines = zenlines[:4]
print (zenlines)
return(zenlines)
==========================================

zenlines = [line.strip('\n'' ') for line in zenlines]


print(zenlines)
return(zenlines)
=============
import io
import re
fp = io.StringIO(zenPython)

#Add Implementation step here


zenlines = fp.readlines()

newzen = [line.strip('\n'' ') for line in zenlines]

data = []
portion = []
for line in newzen:
if(line.find("--") != -1):
data = line.split("--")

if(len(data) == 3):

portion.append(data[1].strip(' '))

if(line.find("*") != -1):
data = line.split("*")

if(len(data) == 3):

portion.append(data[1].strip(' '))

return (portion)

========================================================================
PDH Try2
========================================================================
# Complete the function below.
def subst(pattern, replace_str, string):
#susbstitute pattern and return it
return re.sub(pattern,replace_str,string)
def main():
addr = ['100 NORTH MAIN ROAD',
'100 BROAD ROAD APT.',
'SAROJINI DEVI ROAD',
'BROAD AVENUE ROAD']

#Create pattern Implementation here


new_address=[]
for i in addr:
new_address.append(subst(r' ROAD',' RD.',i))
return new_address
#Use subst function to replace 'ROAD' to 'RD.',Store as new_address
=========================================================================

You might also like