20th July 2024
Post your solution here for the following problem:
Make a program which reads the following file: 100-Contacts.csv
Make sure to use the built in fuctions of python to open and read the files
Using the built in python collections and by the help of regular expressions, do the following:
1) Extract the email addresses
2) Extract the first name of every customer
3) Find out how many times the county named Los Angeles is repeated.
4) List the phone numbers of those who are living in Boston city.
You should not use pandas and numpy. Try solving it by normally reading the file and by using regular expressions.
20 Jul 2024
Share
Rishiraj Roy says:
txt=open("100-contacts.csv",mode='r')
li=[]
for i in txt:
li.append(i)
print(li)
li2=[]
for i in li:
li2.append(i.split(','))
print(li2)
emails=[]
name=[]
LA=0
phno=[]
for i in range (1,100):
name.append(li2[i][0]+' '+li2[i][1])
emails.append(re.findall(r'[\w\.-]+@[\w\.-]+',li[i]))
if 'Los Angeles' in li[i]:
LA+=1
if 'Boston' in li2[i][4]:
phno.extend([li2[i][8],li2[i][9]])
print("Phone numbers of people living in Boston:",phno)
print("No. of times LA is repeated:", LA)
print("Names:", name)
print("Emails:", emails)
Rishiraj Roy says:
https://colab.research.google.com/drive/16_wnG2UaWQboVrYuRl2lbL9CHBtFpyT2?usp=sharing