WHAT CAN I USE TO SORT WITHOUT USING PANDAS, LAMBDAS OR ITEMGETTER?   import csv manufacturerList = [] priceList = [] serviceList = [] with open('ManufacturerList.csv', 'r') as man_list: ml = csv.reader(man_list, delimiter=',') for row in ml: manufacturerList.append(row) print(row) with open('PriceList.csv', 'r') as price_list: pl = csv.reader(price_list, delimiter=',') for row in pl: priceList.append(row) print(row) with open('ManufacturerList.csv', 'r') as service_list: sl = csv.reader(service_list, delimiter=',') for row in sl: serviceList.append(row) print(row) new_mfl = (sorted(manufacturerList, key='id')) new_prl = (sorted(priceList, key='None')) new_sdl = (sorted(serviceList, key='None')) for x in range(0, len(new_mfl)): new_mfl[x].append(priceList[x][1]) for x in range(0, len(new_mfl)): new_mfl[x].append(serviceList[x][1]) new_list = new_mfl inventoryList = (sorted(list, key=1)) with open('FullInventory.csv', 'w') as inventory_file: csv_writer = csv.writer(inventory_file) for i in range(0, len(inventoryList)): csv_writer.writerow(inventoryList[i]) item_type = inventoryList tower_list = [] laptop_list = [] phone_list = [] for i in range(0, len(item_type)): if item_type[i][2] == 'tower': tower_list.append(item_type[i]) elif item_type[i][2] == 'phone': phone_list.append(item_type[i]) elif item_type[i][2] == 'laptop': laptop_list.append(item_type[i]) with open('LaptopInventory.csv', 'w') as new_file1: laptop_writer = csv.writer(new_file1) for i in range(0, len(laptop_list)): laptop_writer.writerow(laptop_list[i]) with open('PhoneInventory.csv', 'w') as new_file2: phone_writer = csv.writer(new_file2) for i in range(0, len(phone_list)): phone_writer.writerow(phone_list[i]) with open('TowerInventory.csv', 'w') as new_file3: tower_writer = csv.writer(new_file3) for i in range(0, len(tower_list)): tower_writer.writerow(tower_list[i]) damaged_list = [] for i in range(0, len(item_type)): if item_type[i][3] == 'damaged': damaged_list.append(item_type[i]) damaged_list = (sorted(damaged_list, key=row[3], reverse=True)) with open('DamagedInventory.csv', 'w') as new_file4: damaged_writer = csv.writer(new_file4) for i in range(0, len(damaged_list)): damaged_writer.writerow(damaged_list[i]) user_man = str(input('Enter manufacturer name: ')) user_type = str(input('Enter your item type: ')) user_item = [] while user_man != 'q': for i in range(0, len(new_list)): if user_man in new_list[i] and user_type in new_list[i]: user_item.append(new_list[i]) if len(user_item) != 0: user_item = sorted(user_item, key=row[4], reverse=True) print('Your item is ', user_item[0]) else: print('No such item in inventory') user_man = str(input('Enter your manufacturer or q to exit: ')) user_type = str(input('Enter your item type: '))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

WHAT CAN I USE TO SORT WITHOUT USING PANDAS, LAMBDAS OR ITEMGETTER?

 

import csv

manufacturerList = []
priceList = []
serviceList = []

with open('ManufacturerList.csv', 'r') as man_list:
ml = csv.reader(man_list, delimiter=',')
for row in ml:
manufacturerList.append(row)
print(row)
with open('PriceList.csv', 'r') as price_list:
pl = csv.reader(price_list, delimiter=',')
for row in pl:
priceList.append(row)
print(row)
with open('ManufacturerList.csv', 'r') as service_list:
sl = csv.reader(service_list, delimiter=',')
for row in sl:
serviceList.append(row)
print(row)

new_mfl = (sorted(manufacturerList, key='id'))
new_prl = (sorted(priceList, key='None'))
new_sdl = (sorted(serviceList, key='None'))

for x in range(0, len(new_mfl)):
new_mfl[x].append(priceList[x][1])

for x in range(0, len(new_mfl)):
new_mfl[x].append(serviceList[x][1])

new_list = new_mfl
inventoryList = (sorted(list, key=1))

with open('FullInventory.csv', 'w') as inventory_file:
csv_writer = csv.writer(inventory_file)
for i in range(0, len(inventoryList)):
csv_writer.writerow(inventoryList[i])
item_type = inventoryList
tower_list = []
laptop_list = []
phone_list = []
for i in range(0, len(item_type)):
if item_type[i][2] == 'tower':
tower_list.append(item_type[i])
elif item_type[i][2] == 'phone':
phone_list.append(item_type[i])
elif item_type[i][2] == 'laptop':
laptop_list.append(item_type[i])
with open('LaptopInventory.csv', 'w') as new_file1:
laptop_writer = csv.writer(new_file1)
for i in range(0, len(laptop_list)):
laptop_writer.writerow(laptop_list[i])

with open('PhoneInventory.csv', 'w') as new_file2:
phone_writer = csv.writer(new_file2)
for i in range(0, len(phone_list)):
phone_writer.writerow(phone_list[i])

with open('TowerInventory.csv', 'w') as new_file3:
tower_writer = csv.writer(new_file3)
for i in range(0, len(tower_list)):
tower_writer.writerow(tower_list[i])
damaged_list = []
for i in range(0, len(item_type)):
if item_type[i][3] == 'damaged':
damaged_list.append(item_type[i])
damaged_list = (sorted(damaged_list, key=row[3], reverse=True))
with open('DamagedInventory.csv', 'w') as new_file4:
damaged_writer = csv.writer(new_file4)
for i in range(0, len(damaged_list)):
damaged_writer.writerow(damaged_list[i])
user_man = str(input('Enter manufacturer name: '))
user_type = str(input('Enter your item type: '))
user_item = []

while user_man != 'q':
for i in range(0, len(new_list)):
if user_man in new_list[i] and user_type in new_list[i]:
user_item.append(new_list[i])

if len(user_item) != 0:
user_item = sorted(user_item, key=row[4], reverse=True)
print('Your item is ', user_item[0])
else:
print('No such item in inventory')
user_man = str(input('Enter your manufacturer or q to exit: '))
user_type = str(input('Enter your item type: '))

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education