Selenium + Python · Lesson 4 of 43

0/43 done

Module 4: Lists, Tuples, Sets & Dictionaries

4. Lists, Dictionaries & Sets for Test Data Structures

16 minlesson

Your task

Implement get_admin_usernames(users_list):

  1. Accept a list of dicts users_list with "username" and "role".
  2. Return a list of usernames where role == "ADMIN".

Write it in the editor, then press Check answer (Ctrl + Enter).

Python Collections in Automation

  1. List: Ordered, mutable sequence (search results, menu tabs).
  2. Dict: Key-value mappings (HTTP headers, user credentials).
  3. Set: Unique items (window handles, unique IDs).
  4. Tuple: Immutable sequence (coordinates, fixed configs).
python
# User credentials dictionary:
user_data = {
    "username": "sdet_user",
    "role": "ADMIN",
    "permissions": ["read", "write", "delete"]
}

# List of dictionaries (test data table):
users = [
    {"username": "admin", "role": "ADMIN"},
    {"username": "guest", "role": "VIEWER"}
]

Key Takeaways & Walkthrough Summary

Lists, dictionaries, and sets are the core data structures used in Python test automation. In this lesson, you will master list operations, dictionary lookups for test parameters, and sets for unique window handles. Let's master collections!

Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

What is the difference between dict['key'] and dict.get('key')?

dict['key'] raises KeyError if the key is missing. dict.get('key') returns None (or a default value) safely without crashing.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip