Python Forum
curious syntax with dictionary item
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
curious syntax with dictionary item
#1
d = {}
a = "hello"
d['x'] = a,
print(d)
Here's the result:

{'x': ('hello',)}

Python created the item as a two-element list maybe?

Consider:

>>> print(d["x"][0])
hello
Do you wonder what element 1 is... I do... anticipation...

IndexError: tuple index out of range Huh
Reply


Messages In This Thread
curious syntax with dictionary item - by inselbuch - Mar-09-2019, 03:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Curious about decorator syntax rjdegraff42 14 2,141 May-03-2023, 01:21 PM
Last Post: rjdegraff42
  python dictionary syntax nafshar 2 886 Apr-24-2023, 07:26 PM
Last Post: snippsat
  Remove an item from a list contained in another item in python CompleteNewb 19 5,792 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  How to modify item in dictionary? Winfried 7 3,485 Nov-21-2020, 07:12 PM
Last Post: bowlofred
  Lists first item is a number however i cant compare it with an int getting syntax err Sutsro 4 2,436 Apr-22-2020, 10:22 AM
Last Post: Sutsro
  A Dictionary in a Dictionary Syntax PythonGainz 3 2,169 Apr-16-2020, 07:16 AM
Last Post: TomToad
  looking fo an expression that yields a dictionary without an item Skaperen 5 2,970 Apr-09-2019, 02:05 AM
Last Post: Skaperen
  deleting item from dictionary Skaperen 6 3,086 Feb-20-2019, 01:18 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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