Bird
0
0

How would you create a dictionary mapping each phase to its order number starting from 1 using a comprehension?

hard📝 Application Q8 of 15
Software Engineering - Fundamentals
You have a list of software phases: ['requirements', 'design', 'implementation', 'testing', 'deployment']. How would you create a dictionary mapping each phase to its order number starting from 1 using a comprehension?
A{i: phase for i, phase in enumerate(phases)}
B{phase: i for i, phase in enumerate(phases, 1)}
C{i+1: phase for i, phase in enumerate(phases)}
D{phase: i+1 for phase, i in enumerate(phases)}
Step-by-Step Solution
Solution:
  1. Step 1: Understand enumerate usage

    enumerate(phases, 1) gives pairs (1, 'requirements'), (2, 'design'), etc.
  2. Step 2: Match dictionary comprehension syntax

    Correct syntax is {phase: i for i, phase in enumerate(phases, 1)} to map phase to order.
  3. Final Answer:

    {phase: i for i, phase in enumerate(phases, 1)} -> Option B
  4. Quick Check:

    Correct dict comprehension maps phase to order [OK]
Quick Trick: Use enumerate with start=1 for ordered mapping [OK]
Common Mistakes:
  • Swapping keys and values
  • Starting enumerate at 0
  • Wrong variable order in comprehension

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Software Engineering Quizzes