Bird
0
0

Which Python code snippet correctly filters a list mac_list to include only MAC addresses starting with the OUI 00:1A:2B?

hard📝 Application Q8 of 15
Computer Networks - Physical and Data Link Layer
Which Python code snippet correctly filters a list mac_list to include only MAC addresses starting with the OUI 00:1A:2B?
Afiltered = [mac for mac in mac_list if mac.endswith('00:1A:2B')]
Bfiltered = [mac for mac in mac_list if '00:1A:2B' in mac]
Cfiltered = [mac for mac in mac_list if mac.upper().startswith('00:1A:2B')]
Dfiltered = [mac for mac in mac_list if mac.lower().startswith('00:1a:2b:3c')]
Step-by-Step Solution
Solution:
  1. Step 1: Understand filtering by OUI

    OUI is the first 3 octets, so MAC addresses must start with '00:1A:2B'.
  2. Step 2: Analyze code snippets

    filtered = [mac for mac in mac_list if mac.upper().startswith('00:1A:2B')] converts MAC to uppercase and checks if it starts with '00:1A:2B' correctly. filtered = [mac for mac in mac_list if '00:1A:2B' in mac] checks if substring is anywhere, which may include false positives. filtered = [mac for mac in mac_list if mac.endswith('00:1A:2B')] checks the end, which is incorrect. filtered = [mac for mac in mac_list if mac.lower().startswith('00:1a:2b:3c')] checks a longer prefix and uses lowercase but with an extra octet, so incorrect.
  3. Final Answer:

    filtered = [mac for mac in mac_list if mac.upper().startswith('00:1A:2B')] -> Option C
  4. Quick Check:

    Filter by startswith OUI in uppercase [OK]
Quick Trick: Use startswith with uppercase OUI to filter MACs [OK]
Common Mistakes:
MISTAKES
  • Checking substring anywhere instead of start
  • Using endswith instead of startswith
  • Mismatching case or extra octets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Computer Networks Quizzes