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...

  • Python Program 5. Write a Python program in a file named validTime.py. Include a function named...

    Python Program 5. Write a Python program in a file named validTime.py. Include a function named string parameter of the form hh:mm: ss in which these are numeric validTime that takes a values and returns True or False indicating whether or not the time is valid. The number of hours, minutes, and seconds must two digits and use a between 0 and 9). The number of hours must be between 0 and 23, the number of minutes and seconds must...

  • l Question 2 -JS and Python a) Write JavaScript code to create a function called "sortstingsDesc"...

    l Question 2 -JS and Python a) Write JavaScript code to create a function called "sortstingsDesc" that will sort an array of string suppiied as a parameter in descending order. (4) Write Python code to create a function called "addToFront" that will accept two parameters the list of information and the value to be added and place the value to the beginning of the list. [4) b)

  • Create a python code named LetterCount with a text file named words.txt that contains at least...

    Create a python code named LetterCount with a text file named words.txt that contains at least 100 words in any format - some words on the same line, some alone (this program involves no writing so you should not be erasing this file). Then create a program in the main.py that prompts the user for a file name then iterates through all the letters in words.txt, counting the frequency of each letter, and then printing those numbers at the end...

  • using Python please reverse file Writ te a function named reverse file. This function will take...

    using Python please reverse file Writ te a function named reverse file. This function will take one parameter which will be the file name of the file to reverse. This function will open the file with the name passed in as a parameter and will print out all the lines of the file in reverse order. Below are a few examples: If the files lines.brt looks like: orange apple orange apple orange apple grape Then the following should look like...

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
ADVERTISEMENT