Question

Create a python file named FQ2 to do the following: - Create a list L. L...

Create a python file named FQ2 to do the following:

- Create a list L.

L = [{'name': 'Sami', 'children': ['Fahad', 'Salwa', 'Khaled']}, {'name': 'Ahmed', 'children': ['Adel', 'Abeer']}, {'name': 'Samia', 'children': []}, {'name': 'Jameela', 'children': ['Najla', 'Salwa', 'Jamal']}]

- Create a function called Populate that takes a list as a parameter.

- The function will add each parent along with his children to the Database.

  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import mysql.connector
conn=mysql.connector.connect(user='',password='',host='',database='')
mycursor=conn.cursor()
def someFunc(*args):
for x in args:
str=''
for y in x:
str="INSERT INTO table_name VALUES('"+y['name']+"'"
for z in y['children']:
str=str+",'"+z+"'"
str=str+");"
mycursor.execute(str)
print(str)
print("\n")
conn.commit()
  
someFunc([{'name': 'Sami', 'children': ['Fahad', 'Salwa', 'Khaled']}, {'name': 'Ahmed', 'children': ['Adel', 'Abeer']}, {'name': 'Samia', 'children': []}, {'name': 'Jameela', 'children': ['Najla', 'Salwa', 'Jamal']}])

Add a comment
Know the answer?
Add Answer to:
Create a python file named FQ2 to do the following: - Create a list L. L...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this problem, assume salesperson data are stored in a database table named staff. Also assume the columns in the table are named name, carsSold, and totalSales Write a Python function named ge...

    For this problem, assume salesperson data are stored in a database table named staff. Also assume the columns in the table are named name, carsSold, and totalSales Write a Python function named getSalesSortedByNames. Your function will have 2 parameters. The first parameter is a database cursor and the second parameter is a float. Your function should start by retrieving those rows in the staff table whose totalsales field is equal to the second parameter. (The next paragraph shows the Python...

  • python Create an empty list of size 100 × 200 with all zeroes. How do you...

    python Create an empty list of size 100 × 200 with all zeroes. How do you access the 4th row and 2nd column of a 2D list called Write a function called printList that takes as a parameter a 2D list and prints it to screen in row/column format. Create a multiplication table of size 10 × 10 that has all the products from 1 times 1 all the way up to 10 times 10. Create a 2D list (matrix)...

  • Create a Python class named Phonebook with a single attribute called entries. Begin by including a...

    Create a Python class named Phonebook with a single attribute called entries. Begin by including a constructor that initializes entries to be an empty dictionary. Next add a method called add_entry that takes a string representing a person’s name and an integer representing the person’s phone number and that adds an entry to the Phonebook object’s dictionary in which the key is the name and the value is the number. For example: >>> book = Phonebook() >>> book.add_entry('Turing', 6173538919) Add...

  • How to do this code? HW13.11. Create an HTML list from a Python list The function...

    How to do this code? HW13.11. Create an HTML list from a Python list The function below takes one parameter: a list, that contains only strings. Complete the function to create a unordered HTML list, as a string, and returns it. An empty list should return an empty HTML list with no list items. Do not add any extraneous whitespace to the HTML. For example, if given the list ["one", "two"], the function should return "<ul><li>one</li><li>two</li> </ul>". student.py IT TI...

  • Create a java program that reads an input file named Friends.txt containing a list 4 names...

    Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do:   1. Add a new name   2. Change a name 3. Delete a name 4. Print the list   or 5. Quit    When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...

  • "PYTHON" 1. a. Create a file (module) named camera_picture.py. b. Write a function, take_picture_effect, that takes...

    "PYTHON" 1. a. Create a file (module) named camera_picture.py. b. Write a function, take_picture_effect, that takes two parameters, the filename and an effect. c. Take a picture with the filename and effect. Use camera.effect to set the effect. Use help(PiCamera) to find the effects which you can apply. d. Create a second file use_camera.py. e. Import the take_picture_effect function from the camera_picture module. f. Prompt the user for the filename. g. Prompt the user for the image_effect. help(PiCamera) to see...

  • Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called...

    Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called HelperClasses and create a class inside it called Helpers Inside Helpers, create 8 static methods as follows: 1.) Max, Min, Standard_Deviation, Mean a.) Each of these should take a list as a parameter and return the calculated value 2.) Bubble a.) This should take a list as a parameter and return the sorted list 3.) Median a.) This should take a list as a...

  • Python: Write a function named "sort_by_length" that takes a list/array of strings as a parameter and...

    Python: Write a function named "sort_by_length" that takes a list/array of strings as a parameter and sorts the strings by their length

  • Need to do in Python? Can do in Javascript but not in Python Write a function...

    Need to do in Python? Can do in Javascript but not in Python Write a function named "indexed_list" that takes a list as a parameter. Your function should create a new array. Update the newly created list so that it has the same number of entries as the function's input. Assign each entry in the list you created the value of it's index. So the entry at index 0 would have the value 0, the entry at index 1 would...

  • using python, Write a function named displayReverse that takes a list as a parameter and DISPLAYS...

    using python, Write a function named displayReverse that takes a list as a parameter and DISPLAYS the contents of the list to the screen in reverse. Submit the code and a screenshot of the program running in Linux

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT