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