Finad all the area codes and mobile prefixes called by people in bangalore. Fixed lines start with an area code neclosed in parenthesis. The area codes vary in length but always begin with 0. Mobile numbers have no parenthesis, but have a space in the middle of the number to help readability. the prefix of a mobile number is its first four digits and they always tart with 7,8, or 9.
Using java -------------
Finad all the area codes and mobile prefixes called by people in bangalore. Fixed lines start with an area code neclosed in parenthesis. The area codes vary in length but always begin with 0. Mobile numbers have no parenthesis, but have a space in the middle of the number to help readability. the prefix of a mobile number is its first four digits and they always tart with 7,8, or 9.
Telemarkets numbers have no parenthese or space, but they start with the area code 140. The return string for outgoingCallsFromBangalore should be all the area codes in lexicographic order with no duplicates.
![](/static/compass_v2/shared-icons/check-mark.png)
import csv
with open('texts.csv', 'r') as f:
reader = csv.reader(f)
texts = list(reader)
with open('calls.csv', 'r') as f:
reader = csv.reader(f)
calls = list(reader)
def filter(calls):
# this function goes through 'calls.txt' and identifies data with the origin from Bangalore. bangalore = list()
for call in calls:
if call[0].startswith('(080)'): bangalore.append(call[1])
return bangalore
def areacode(bangalore):
''' Depending on the type of phone number, add the area code to the list if it is not a duplicate ''' code_list = list()
for phone_n in bangalore:
if phone_n.startswith('('):
end = iter_fixed(phone_n)
temp = phone_n[0:end+1]
if temp not in code_list: code_list.append(temp)
elif phone_n.startswith('7' or '8' or '9'):
end = iter_mobile(phone_n)
temp = phone_n[0:end]
if temp not in code_list: code_list.append(temp)
else: temp = '140'
if temp not in code_list: code_list.append(temp)
return code_list
def iter_fixed(phone_n):
# extracting area code for fixed numbers i=0 while phone_n[i] != ")":
i = i+ 1
return idef iter_mobile(phone_n):
# extracting area code for mobile numbers i=0 while phone_n[i] != " ":
i = i+1
return i
def printline():
# prints codes one for each line.
# RUNTIME ANALYSIS: The whole program is run in O(n^2log(n)) time because
# all functions are in O(n) but I run sorted on top of that? -> Question. codes = sorted(areacode(filter(calls)))
for i in codes:
print(i)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)