Reputation: 13
I've been working on a lab for my scripting class, where I need the loop to go through each system in a list of systems and call a function to check if the users in a system have admin access. The way my code is running results in the "for system in systems" part calling a function with the entire systems tuple instead of just one system.
A sample of the code to show what I mean:
systems = [
[('System1',
{'users': [('alice', 'admin'), ('bob', 'user')]}),
('System2',
{'users': [('charlie', 'guest'), ('dave', 'admin')]}) ]
admin_status = []
for system in systems:
admin.append(audit_permissions(system))
def audit_permissions(system: tuple) -> dict:
system_name = system[0]
system_info = system[1]
This results in system_name = ('System1', {'users': [('alice', 'admin'), ('bob', 'user')]}) and system_info = ('System2', {'users': [('charlie', 'guest'), ('dave', 'admin')]}) rather than system_name = 'System1' and system_info = {'users': [('alice', 'admin'), ('bob', 'user')]}, and I can't return the result correctly.
It's very possible that this is a simple mistake, but I couldn't find an answer online, and it's been a while since I've used python last. Is the "for system in systems" incorrect, or am I doing it wrong? Any help is appreciated, and thanks in advance!
Upvotes: -4
Views: 44