Python Forum
How does this code know to use the key of a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does this code know to use the key of a dictionary
#2
(Feb-15-2020, 08:13 PM)renveg Wrote: My question is, how does the program know that I want the key returned from the variable account? How could I use the key and return the value?

if you enter in the command line python password.py email,
the 'account' variable (line #11) will be set to email (a string). Further, the program checks if the record named 'email' exists in PASSWORD dictionary and tries to get corresponding password for the account (email): PASSWORD[account]. pyperclip.copy is copying the value of password (in case of 'email' account it would be 'incospmei#$%') to clipboard. Finally, you get information that password was copied (line #15). Hope that helps.
Reply


Messages In This Thread
RE: How does this code know to use the key of a dictionary - by scidam - Feb-15-2020, 11:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary within html code ebolisa 4 2,812 Aug-09-2021, 11:36 AM
Last Post: ebolisa
  Iterating over a dictionary in a for loop - checking code has worked sallyjc81 1 2,065 Dec-29-2020, 05:14 PM
Last Post: ndc85430
  Line of code to show dictionary doesn't work MaartenRo 2 2,578 Jul-28-2020, 03:58 PM
Last Post: deanhystad
  Why does my code not execute? (def function with 'for in' iteration over a dictionary Placebo 3 3,070 Oct-19-2018, 01:32 PM
Last Post: Placebo

Forum Jump:

User Panel Messages

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