Regarding the Dict() function

Q: How would multiple sets of starlines be printed concurrently if Key: ‘a’ was involved??

(All codes following the first line are unnecessary. Tried for loop as well…)

A = {'a': {x*y for x in range(7) for y in range(7)}, 'p': print ('******') }
a = int()
b = a
while True:
    a = b
    A['p']

The 'p': print('******') part means to print the stars now, and use the result from print as the value for the 'p' key. The result is None, because print displays text as a side effect and returns None. Inside the loop, A['p'] does nothing useful; simply looking up a value in a dict can’t cause the function to run. All of that part already happened; lookup is just lookup.

If you just store print in the dictionary, then you can retrieve it and call it later:

A = {'a': {x*y for x in range(7) for y in range(7)}, 'p': print }
while True:
    A['p']('******')

But with this technique, you have to say what to call it with, when you call it. Because the way that you say what the arguments are, is the actual call.

If you want to “store” the argument so that it’s decided ahead of time, really what you are trying to do is make a new function, that doesn’t want any arguments, and just always prints the '******' string when it is called. There are a few techniques for this:

1 Like

I can’t understand how you want to “involve” this key - why it should be useful to help solve the problem. I also don’t understand exactly what you want to be printed. But I think you should first check the result from {x*y for x in range(7) for y in range(7)}. I know what it does, but I think you might be surprised. I can’t really tell what you want it to do.

You are incredible!

Works now.

My lack of understanding regarding the relationships between list(), set(), and dict() is one of my many issues.

A = {'a': {x*y for x in range(7) for y in range(7)}, 'p': print }
for xy in range(7):
    A['p']('******')

I thought of x and y as x and y coordinates. The transition between mental geometry and written math (plus Python syntax) is quite challenging.

@kknechtel

Thanks again…