Informatics2-2021/Lab10

A MathWikiből
(Változatok közti eltérés)
(Exercise)
(write_json)
20. sor: 20. sor:
  
 
==write_json==
 
==write_json==
Write a json file that contains the same information as our two .csv files.<br>
+
Write a json file that contains your name and one of of your friends and your favorite movies( several movies can be listed) .<br>
Its name should be sample.json, it should have two keys: first and second.<br>
+
Its name should be sample.json, it should have two keys: "first" contains your information and "second" contains your friend informations .<br>
 
Each key should have a list of some of the information in .csv in some meaningful key: value pair format.<br>
 
Each key should have a list of some of the information in .csv in some meaningful key: value pair format.<br>
 
For example, for me:
 
For example, for me:
  {'first': {'Name': 'Muhammad Imran', 'My favorite film': 'Among the stars'}, 'second': {'Name': 'Muhammad Imran', 'What kind of occupation would I choose': ['Gardener' , 'Detective']}}
+
  {'first': {'Name': 'Muhammad Imran', 'favorite movie': 'Among the stars'}, 'second': {'Name': 'Zong', 'favorite movie': ['It' , 'Iron man']}}

A lap 2021. április 21., 10:21-kori változata

Home

Tartalomjegyzék

Exercise

write_csv

Write the first.csv and second.csv files based on what you learned in the lecture.

In the first.csv:

enter your first and last names separated by a comma in the first line. 
In the second line, separate the title of your favorite movie with a comma, when it was made and the name of the actor and the director from the movie.

In the second.csv:

Enter your last names and first names with a tab in the first line.
In the second line, write which area of mathematics interests you the most.
And the third line is what you would like to work on in the future (several things can be listed).

read_csv

Write a function that reads a .csv file.
The function should have an optional delimiter parameter with a default value of ','.
Write that the function works even if the values in the file are not separated by ',' but by tabs. (In this case, the input delimiter = '\ t' also indicates this, it does not need to be detected automatically.)
The function returns a list of lists in which the lists correspond to the rows and the elements are the words in the row separated accordingly.

write_json

Write a json file that contains your name and one of of your friends and your favorite movies( several movies can be listed) .
Its name should be sample.json, it should have two keys: "first" contains your information and "second" contains your friend informations .
Each key should have a list of some of the information in .csv in some meaningful key: value pair format.
For example, for me:

{'first': {'Name': 'Muhammad Imran', 'favorite movie': 'Among the stars'}, 'second': {'Name': 'Zong', 'favorite movie': ['It' , 'Iron man']}}
Személyes eszközök