Dennis, I am replying to the group but mainly you as I doubt Nati really reads much of what we write.
The use of list() is needed as what comes out of the function may be an object of type dict_keys which is iterable but if you want it in a list form all at once, the idiom he uses is common. In the code below, alternating lines are commands and output, shown by blank lines between pairs. a={"aleph":1,"bet":2, "ג":3} a {'aleph': 1, 'bet': 2, 'ג': 3} a.keys() dict_keys(['aleph', 'bet', 'ג']) list(a.keys()) ['aleph', 'bet', 'ג'] The question you ask is what I speculated on. Is he looking for the content of a specific key in his dictionary called "a" to be something with multiple values like a list or dictionary. BUT my question is whether reading it into numpy and converting the top level to a dictionary, results in being able to store another dictionary within it, or leaves some other data structure that maybe he needs to also be converted, if that can be done. I could waste more time playing around but Nati is not an ideal partner to engage with. I experiment with embedding a dictionary within itself as the second entry and it works fine BUT I bet what Nati has is not that as it was not made like that: a["bet"] = a a {'aleph': 1, 'bet': {...}, 'ג': 3} a["bet"]["aleph"] 1 Now if Nati gave a damn he should do something like I am doing and run his code part way and LOOK at what he has before continuing to use it as if it is what he imagines, or worse, he is copying only part of a recipe cobbled together. And, agreed, Nati has so many things that look like errors, that it is silly to ask why the mess did not work, and better to ask how each piece starting from the top is working or should be adjusted to work. -----Original Message----- From: Python-list <python-list-bounces+avi.e.gross=gmail....@python.org> On Behalf Of Dennis Lee Bieber Sent: Friday, July 15, 2022 1:11 PM To: python-list@python.org Subject: Re: [Neuroimaging] what's the problem?????? On Thu, 14 Jul 2022 17:20:55 -0400, <avi.e.gr...@gmail.com> declaimed the following: >Dennis, > >I see Nati sent some more code without explaining again what he wants. Yes, somewhere in this stack of messages he may have said things (that we generally failed to understand) but it would be helpful to summarize WHY he sent us what he did or which lines to look at. > And that code seems to be doing a lot of repetitive/unneeded operations... Nothing from from nilearn import ... to masker = ... appears to depend upon the file name "nii" in the loop and should be refactored to the top-level. The try/except block for sklearn looks like another candidate to be pulled out of the file loop. > If your suggestion is right, he may not understand dictionaries as a hashed data structure where you can access a.items() or a.keys() or a.values() if you want a list of sorts of the parts, or a[key] if you want a particular part. > So far as I can tell, the OP only references ONE key in the dictionary, but apparently expects that key to have multiple values. Yet there doesn't seem to be a structure /holding/ multiple values -- unless a["Difumo_names"] is, itself, returning a dictionary on which .values() can be applied. In that case, the list() call is likely redundant as .values() already returned a list (hmmm, is list(some_list) a no-op, or does it wrap some_list into another list -- in the latter case, the indexing will fail as there is only one element to access) > for i in estimator.covariance_: > r=list(a["Difumo_names"].values())[jsa] > jsa=jsa+1 > a=dict() And there is the biggest fault... The OP is completely obliterating the "a" dictionary, so subsequent passes in that loop have nothing to look up. "aas" gets initialized as a dictionary using {}, and never gets any key:value pairs assigned to it, yet there is a print(aas) in the code. And that is as far as I can guess -- given the lack of example input data, example /desired/ output... etc. There are too many apparent errors in that code sample to even attempt to think what a result could be. -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list