Question

In: Computer Science

PHTHON 3 Write code that generates a list of the names of all the senders of...

PHTHON 3

Write code that generates a list of the names of all the senders of the messages in fb_data. Store it in a variable called senders.

fb_data = {
"data": [
{
"id": "2253324325325123432madeup",
"from": {
"id": "23243152523425madeup",
"name": "Jane Smith"
},
"to": {
"data": [
{
"name": "Your Facebook Group",
"id": "432542543635453245madeup"
}
]
},
"message": "Understand. Extract. Repeat.",
"type": "status",
"created_time": "2014-10-03T02:07:19+0000",
"updated_time": "2014-10-03T02:07:19+0000"
},

{
"id": "2359739457974250975madeup",
"from": {
"id": "4363684063madeup",
"name": "John Smythe"
},
"to": {
"data": [
{
"name": "Your Facebook Group",
"id": "432542543635453245madeup"
}
]
},
"message": "Here is a fun link about programming",
"type": "status",
"created_time": "2014-10-02T20:12:28+0000",
"updated_time": "2014-10-02T20:12:28+0000"
}]
}

Solutions

Expert Solution

Solution:

Look at the code and comments for better understanding.................

Screenshot of the code:

Output:

Code to copy:

fb_data = {
        "data": [
                {
                        "id": "2253324325325123432madeup",
                        "from": {
                                "id": "23243152523425madeup",
                                "name": "Jane Smith"
                        },
                        "to": {
                                "data": [
                                        {
                                        "name": "Your Facebook Group",
                                        "id": "432542543635453245madeup"
                                        }
                                ]
                        },
                        "message": "Understand. Extract. Repeat.",
                        "type": "status",
                        "created_time": "2014-10-03T02:07:19+0000",
                        "updated_time": "2014-10-03T02:07:19+0000"
                },
                {
                        "id": "2359739457974250975madeup",
                        "from": {
                                "id": "4363684063madeup",
                                "name": "John Smythe"
                        },
                        "to": {
                                "data": [
                                        {
                                                "name": "Your Facebook Group",
                                                "id": "432542543635453245madeup"
                                        }
                                ]
                        },
                        "message": "Here is a fun link about programming",
                        "type": "status",
                        "created_time": "2014-10-02T20:12:28+0000",
                        "updated_time": "2014-10-02T20:12:28+0000"
                }
        ]
}
#senders ia list variable that stores all the names of the senders
senders = []
#iterate over every detail of the data list
for detail in fb_data["data"]:
        #get the name of the sender from the dictionary having the key "from"
        name = detail["from"]["name"]
        senders.append(name)
print("Senders Names :")
print(senders)

​​​​​​​I hope this would help.............................:-))


Related Solutions

Write SQL queries below for each of the following: List the names and cities of all...
Write SQL queries below for each of the following: List the names and cities of all customers List the different states the vendors come from (unique values only, no duplicates) Find the number of customers in California List product names and category descriptions for all products supplied by vendor Proformance List names of all employees who have sold to customer Rachel Patterson
Write code to read a list of song names and durations from input. Input first receives...
Write code to read a list of song names and durations from input. Input first receives a song name, then the duration of that song. Input example: Time 424 Money 383 quit. #include <iostream> #include <string> #include <vector> using namespace std; class Song { public: void SetNameAndDuration(string songName, int songDuration) { name = songName; duration = songDuration; } void PrintSong() const { cout << name << " - " << duration << endl; } string GetName() const { return name;...
Given a list of items, write a program that generates a list of lists of the...
Given a list of items, write a program that generates a list of lists of the following form: [a,b,c,...,z]⇒[[z], [y,z], [x,y,z], ... , [a,b, ... ,y,z]] Hint: Slicing is your friend. please write a python program
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g....
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g. (“John”, “Doe”) that represents a class. Ask the user for a students first and last name and check if that student is a member of the class.
Write a for-loop in MATLAB that generates a list of numbers such that each number is...
Write a for-loop in MATLAB that generates a list of numbers such that each number is the sum of the previous three. Initialize your list of numbers at the values of 0, 0 and 1. In other words, "0" is the first element of the list, "0" is the second element of the list, and "1" is the third element of the list. What is the 20th value in the list?
PHP Question: Write the PHP code to list out all of the dates of the current...
PHP Question: Write the PHP code to list out all of the dates of the current month and assign them to their given days. As an example, for the month of October 2020, the output should look something like this: October 2020       Monday: 5, 12, 19, 26 Tuesday: 6, 13, 20, 27 Wednesday: 7, 14, 21, 28 Thursday: 1, 8, 15, 22, 29 Friday: 2, 9, 16, 23, 30 Saturday: 3, 10, 17, 24, 31 Sunday: 4, 11, 18,...
Write the python code that generates a normal sample with given μ and σ, and the...
Write the python code that generates a normal sample with given μ and σ, and the code that calculates m (sample mean) and s (sample standard deviation) from the sample.
Write the python code that generates a normal sample with given μ and σ, and the...
Write the python code that generates a normal sample with given μ and σ, and the code that calculates m and s from the sample. Do the same using the Bayes’ estimator assuming a prior distribution for μ.
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
C++ Write a program that reads in a list of 10 names as input from a...
C++ Write a program that reads in a list of 10 names as input from a user and places them in an array. The program will prompt for a name and return the number of times that name was entered in the list. The program should output total number of instances of that name and then prompt for another name until the word done is typed in. For this lab, use the string data type as opposed to char to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT