Gaining Insights

Flattening & Comparing

Now let's use the two functions we added earlier to format our results.

First, we'll use the flatten() function to flatten the JSON structure that the analyze() function returns, like so:

#First, flatten the results from the Watson PI API
user = flatten(user_result)
celebrity = flatten(celebrity_result)

Then, we'll use the compare() function to compare the user and celebrity in order to gain insights on their personalities.

#Then, compare the results of the Watson PI API by calculating the distance between traits
compared_results = compare(user,celebrity)
Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.