Python Forum
Add elements to a Dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add elements to a Dictionary
#12
muzikman Wrote:You're appending a tuple but each tuple has an identifier 'Title' and 'Rating'.
Does this associate the key with the value here? My solution wouldn't have had a key reference
It's make the tuple easier to convert to a dictionary.
So this is the convert part,see that in Python easy take out small part and do test interactively.
>>> t = (('Title', '1,000 Places to See Before You Die'), ('Rating', 'Five'))
>>> dict((y, x) for y, x in t)
{'Title': '1,000 Places to See Before You Die', 'Rating': 'Five'}
>>> d['Rating']
'Five'
>>> d['Title']
'1,000 Places to See Before You Die'
Quote:In more powerful ORMs you can relate these tablets that just take a collection of Movies, People and insert them with one insert. It will automatically add the corresponding data in the join table. I used Laravel the PHP framework and their ORM was awesome. I used it to harvest data from a few movie restful APIs. The response was all JSON and I would turn the JSON into PHP objects, then use the ORM to insert A Movie and the entire cast of people with one call, over three tables. The framework is now way over bloated and is basically another copy of Symfony framework.
If doing this on web with Python i would use Flask with Flask-SQLAlchemy
Django is ok if want a larger web-framework with most stuff build in.
FastAPI is the new start ✨
Reply


Messages In This Thread
Add elements to a Dictionary - by muzikman - Sep-08-2021, 07:29 PM
RE: Add elements to a Dictionary - by deanhystad - Sep-08-2021, 07:31 PM
RE: Add elements to a Dictionary - by Yoriz - Sep-08-2021, 07:42 PM
RE: Add elements to a Dictionary - by muzikman - Sep-08-2021, 07:46 PM
RE: Add elements to a Dictionary - by perfringo - Sep-08-2021, 07:52 PM
RE: Add elements to a Dictionary - by snippsat - Sep-09-2021, 12:54 AM
RE: Add elements to a Dictionary - by naughtyCat - Sep-09-2021, 05:33 AM
RE: Add elements to a Dictionary - by deanhystad - Sep-09-2021, 06:39 AM
RE: Add elements to a Dictionary - by muzikman - Sep-09-2021, 12:40 PM
RE: Add elements to a Dictionary - by snippsat - Sep-09-2021, 07:03 PM
RE: Add elements to a Dictionary - by muzikman - Sep-09-2021, 07:36 PM
RE: Add elements to a Dictionary - by snippsat - Sep-10-2021, 03:08 PM
RE: Add elements to a Dictionary - by muzikman - Sep-10-2021, 03:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,197 May-17-2022, 11:38 AM
Last Post: Larz60+
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,634 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  Looping through dictionary and comparing values with elements of a separate list. Mr_Keystrokes 5 3,931 Jun-22-2018, 03:08 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020