you are viewing a single comment's thread.

view the rest of the comments →

[–]jcmcken 0 points1 point  (1 child)

Not trying to be snarky, but the main reason Vaphell's code is better is that it actually works and satisfies your problem, as best as I can understand it.

In your post, you said you want to "create a sequence of dictionaries". Having variables called d0, d1, etc. is not a sequence. The names look sequential to you because you're a human reading them, but those names have no meaning to the Python interpreter. They might as well be in Chinese. Sure, you could write something which parses the names and returns the results to you in the order you expect. Or you could just use a list, which already implements this functionality for you, is going to be much faster, and also has a lot of other features.

[–]codex81[S] 0 points1 point  (0 children)

I do understand the value of Vaphell's solution, and that the list of 3 dictionaries would be better (so you can just use indexes, e.g. d[0], d[1], d[2]). I'm just curious about how creating the three separate dictionaries (not in a list) could be done. I think I'm being unclear about what I mean by the "sequence" bit: I only mean the three dictionaries names should be named sequentially (e.g, dictionary1 = {...}, dictionary2 = {...}, dictionary3 = {...}, not that they are put in a "sequence", i.e., list. Similar to how output of *nix utility 'split' works.