Python Forum
variable as dictionary name?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable as dictionary name?
#1
Hi I am attempting to create 10 dictionaries without having to code them explicitly.
The names of the dictionaries will be: X0, X1, X2, X3 .... X9

for x in range(11):
		a = str(x)
		dictionary_name = ('X'+a)
		dictionary_name = {}

        
if i add type(dictionary_name) to the code it returns 'dict' However if i try to print one of the dictionaries print (dictionary_name) i get


Error:
NameError: name 'X0' is not defined
Reply


Messages In This Thread
variable as dictionary name? - by diazepam - Apr-27-2020, 04:05 AM
RE: variable as dictionary name? - by ndc85430 - Apr-27-2020, 04:08 AM
RE: variable as dictionary name? - by diazepam - Apr-27-2020, 04:25 AM
RE: variable as dictionary name? - by ndc85430 - Apr-27-2020, 04:31 AM
RE: variable as dictionary name? - by deanhystad - Apr-27-2020, 08:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reference new dictionary keys with a variable slouw 4 2,918 May-07-2019, 03:30 AM
Last Post: slouw
  Dictionary named after variable value Alfred 1 3,066 Sep-02-2017, 01:24 PM
Last Post: sparkz_alot
  Build a multi-variable dictionary birdieman 4 5,037 Jan-06-2017, 04:34 PM
Last Post: birdieman
  calling an object variable in a dictionary sunhear 3 4,316 Dec-30-2016, 05:28 PM
Last Post: sunhear

Forum Jump:

User Panel Messages

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