-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Appending to array inside dictionary #3931
Comments
This is the intended behaviour. All objects are immutable, you can not change the contents of them. You can only create new ones. (which is what += does behind the scenes). Once #3905 lands you should be able to do something like: update = {'key': d['key'] + ['new_thing']}
d += update |
Oh, I see. I was asking because the following: foreach type, list : supported_backends
if type == 'video'
list += darwin_supported_backends.get('video')
elif type == 'audio'
list += darwin_supported_backends.get('audio')
endif
endforeach is working quite well. So I was curious if I could shorten the code ! |
Is it? Because I tested it and it doesn't: backends = {'video': ['foo'], 'audio': ['bar']}
message(backends)
foreach type, list : backends
message(list)
if type == 'video'
list += ['faz']
else
list += ['baz']
endif
message(list)
endforeach
message(backends) Outputs this:
So |
Yes, @nirbheek you are totally right. I hurried to conclusions 😓. I assumed that if it's syntactically correct, then it is working for sure. My bad. Just gonna wait for that PR to land. But now I guess I only can solve the issue by using multiple variables instead of the dictionary. |
Hello ! Love the dictionary feature, however It seems that I can't add new values to the array inside of the dictionary. I am trying to ensure that the user selected available build options for the platform, and to do so I populate
supported_backends.get('video')
with platform-specific video backendsdarwin_supported_backends.get('video')
, both dictionary values are arrays. Here is code snippet:And here is the build log (with omitted path, I hope it's ok to do that):
I found nothing regarding this in the documentation, so not sure if I'm doing something wrong and this is intended behavior.
The text was updated successfully, but these errors were encountered: