Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a python csv question. the 1st question probably require nested loop import csv, json alist ((Legends, Nickname), (Kobe Bryant, Mamba), (Shaq, Shaq Daddy), [Calvin Johnson,

image text in transcribed
a python csv question. the 1st question probably require nested loop
import csv, json alist (("Legends", "Nickname"), ("Kobe Bryant", "Mamba"), ("Shaq", "Shaq Daddy"), ["Calvin Johnson", "Megatron"]] Question 1 - Return a list of dictionaries with the keys being the fieldnames and the values being the respective values in each row - The parameter alist is a list of lists, with the oth index being the fieldnames - DO NOT HARD CODE the keys to each dictionary, we will test your code with different data . - e.g >> alist = (("Legends", "Nickname"), ("Kobe Bryant", "Mamba"), ("Shaq", "Shaq Daddy"), ("Calvin Johnson", "Megatron"]] >> print(list_of_lists_to_list_of_dicts(atist)) ('Legends': 'Kobe Bryant', 'Nickname': 'Mamba'), ('Legends': 'Shaq', 'Nickname': 'Shaq Daddy'), ('Legends': 'Calvin Johnson', 'Nickname''Megatron'] def list_of_lists_to_list_of_dicts(alist): pass Question 2 - Write a function that writes the header and each row of data to the csv file name specified in the parameter. Return the number of rows written to the file, NOT including the header ters alist follows the same structure as alist in Questioni, Tilename will include the file extension (e.g. "filename.csv") - Hint: call list_of_lists_to_list_of_dicts to convert the list of lists to list of dicts before writing using csv.Dictwriter e.g. >> alist = [["Legends","Nickname"), ("Kobe Bryant", "Mamba"), ("Shaq", "Shaq Daddy"] , ["Calvin Johnson", "Megatron"]] >> print(list_of_lists_to_cavalist, 'output.csv')); The example csv should look like the following: Legends,Nickname Kobe Bryant, Mamba Shaq, Shaq Daddy Calvin Johnson, Megatron def list_of_lists_to_csv(alist, filename): pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

Relational Contexts in Organizations

Answered: 1 week ago