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
3) How to write a code for a 'menu' in c++? write all of the possible...
3) How to write a code for a 'menu' in c++? write all of the possible ways with steps
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 μ.
Write shell script code that displays a list of all active processes in the system. Lift...
Write shell script code that displays a list of all active processes in the system. Lift the BSD-style “only yourself” restriction. The output should show the status of the processes. #!/bin/bash while [[ $REPLY != x ]]; do clear echo -e "Launch utilities:\n 1. Process Tree\n 2. Process States\n 3. Threads\n" read -p "Enter selection [1-3], or type x to exit: " REPLY if [ $REPLY == 1 ]; then    echo -e "\n"    #identify a command that displays...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT