In CBSE 083 dictionary-to-stack problems, you traverse `emp_dict.items()` (or iterate keys) and test `salary > 50000` strictly using `>` rather than `>=`. Whenever the condition holds, `stack.append(name)` pushes only the employee name onto the stack. Next, a `while stack:` loop pops and prints each name in reverse order of dictionary insertion, outputting `"Empty"` or `"Underflow"` once `len(stack) == 0`.
- 1. Unpacking Dictionary Key-Value Pairs for Filtering
- 2. Popping Filtered Names in LIFO Sequence
- 3. Handling Nested Dictionaries and Real-World Variations
- 4. Push and Pop Employee Names With Salary Above 50000 From Dictionary
- 5. Step-by-Step Dictionary Filtering Trace (Salary > 50000)
- 6. Common Mistakes & Top Scorer Tips
- 7. Interactive Concept Check Quiz
- 8. Frequently Asked Questions
1. Unpacking Dictionary Key-Value Pairs for Filtering
CBSE Class 12 Computer Science papers commonly represent employee records as a dictionary mapping `Name: Salary`, such as `{'Rohan': 48000, 'Meera': 62000, 'Kabir': 50000, 'Ananya': 75000}`. To process both fields cleanly without extra dictionary lookups, loop with `for name, salary in emp_dict.items():`. Check the boundary operator carefully: the prompt asks for salary greater than `50000`, so `50000` itself must be excluded using strict `>`. Notice also what gets pushed onto the stack: the question asks for a stack of employee names, not `(name, salary)` tuples and not salary integers. Pushing `name` directly keeps the stack uniform (`['Meera', 'Ananya']`) and guarantees full marks on CBSE 083 evaluation rubrics that inspect both filter condition and pushed payload type.
- Unpack keys and values cleanly with `emp_dict.items()` to avoid repeated key lookups.
- Use strict `salary > 50000` so boundary values equal to `50000` are excluded.
- Append only `name` to the stack unless the question explicitly requests `[name, salary]` pairs.
2. Popping Filtered Names in LIFO Sequence
After `PushEmp(emp_dict)` populates the stack list, the companion `PopEmp()` function removes and displays each qualifying employee name until the stack becomes empty. Because Python 3.7+ dictionaries preserve insertion order, `items()` visits entries sequentially, meaning the last qualifying employee in the dictionary lands at the top of the stack. Consequently, `PopEmp()` outputs names in reverse insertion order. Writing `while len(stk) > 0: print(stk.pop())` followed by `print("Stack Empty")` after the loop—or an explicit `if not stk:` guard when invoked on an already-empty stack—satisfies both the pop logic and the underflow termination requirement expected by CBSE board evaluators. Avoid indexing `stk[0]` or using `del stk[-1]` without capturing the popped value first.
- Pop elements using `while len(stk) > 0:` so every qualifying name is printed in LIFO order.
- Always emit `"Stack Empty"` or `"Underflow"` when popping an empty stack or after draining it.
- Never use `del stk[-1]` without retrieving the popped name first, as board outputs require printing each popped value.
3. Handling Nested Dictionaries and Real-World Variations
Some CBSE sample papers and pre-board sets supply a nested dictionary or dictionary of lists instead of `{Name: Salary}`, for instance `{'E101': {'name': 'Meera', 'salary': 62000}}` or `{'E101': ['Meera', 62000]}`. Understanding how to adapt your lookup expression—`details['salary'] > 50000` or `details[1] > 50000`—while keeping the exact same `push_high_earners()` and `pop_all()` stack structure makes you ready for any question twist. Also check whether the board question specifies a global stack variable like `EmpStack = []` with zero-argument `Push()`/`Pop()` functions or passes the stack list as a parameter. Practicing both function signatures prevents accidental `TypeError` deductions when translating pseudocode into complete Python answers.
- Adapt `salary` access to `val[index]` or `val['salary']` when dictionary values are lists or nested dicts.
- Check whether the prompt specifies a global stack list or expects the stack as a parameter.
- Ensure the dictionary keys and values match the exact data types assumed in your comparison.
4. Push and Pop Employee Names With Salary Above 50000 From Dictionary
def push_employees(emp_dict, stack):
for name, salary in emp_dict.items():
if salary > 50000:
stack.append(name)
print(f"Pushed: {name} (Salary: {salary})")
def pop_employees(stack):
if len(stack) == 0:
print("Stack Empty")
return
print("Popping employees with salary > 50000:")
while len(stack) > 0:
print("Popped:", stack.pop())
print("Stack Empty")
employees = {
"Emp101": 45000,
"Emp102": 68000,
"Emp103": 50000,
"Emp104": 82000,
"Emp105": 54000,
}
emp_stack = []
push_employees(employees, emp_stack)
print("Current Stack:", emp_stack)
pop_employees(emp_stack)
Verified Console / Dry-Run Output:
Pushed: Emp102 (Salary: 68000)
Pushed: Emp104 (Salary: 82000)
Pushed: Emp105 (Salary: 54000)
Current Stack: ['Emp102', 'Emp104', 'Emp105']
Popping employees with salary > 50000:
Popped: Emp105
Popped: Emp104
Popped: Emp102
Stack Empty
5. Step-by-Step Dictionary Filtering Trace (Salary > 50000)
| Employee Key | Salary Value | Passes `> 50000`? | Stack Action Taken |
|---|---|---|---|
| Emp101 | 45000 | No | Skipped |
| Emp102 | 68000 | Yes | Pushed (`['Emp102']`) |
| Emp103 | 50000 | No (boundary excluded) | Skipped |
| Emp104 | 82000 | Yes | Pushed (`['Emp102', 'Emp104']`) |
| Emp105 | 54000 | Yes (TOP) | Pushed (`['Emp102', 'Emp104', 'Emp105']`) |
Practice CBSE 083 Stack Questions 1-on-1 With 4Achievers Junior
Master CBSE 083 dictionary-to-stack questions with personalized dry-run coaching and mock board drills in 4Achievers Junior 1-on-1 or 1:4 Micro-Pods (Grades 3-12).
6. Common Mistakes & Top Scorer Tips
- Avoid Mistake: Using `>= 50000` instead of `> 50000`, mistakenly pushing an employee whose salary is exactly `50000`.
- Avoid Mistake: Pushing the salary value or `(name, salary)` tuple onto the stack when the question asks only for employee names.
- Avoid Mistake: Iterating `for name in emp_dict:` and comparing `name > 50000`, which compares a string against an integer and raises `TypeError`.
- Avoid Mistake: Omitting the `"Stack Empty"` output after all qualifying names have been popped.
- Examiner / Mentor Tip: Underline `>` vs `>=` in the question paper before coding—boundary errors cost 0.5 marks in CBSE 083 evaluation.
- Examiner / Mentor Tip: Verify whether the question asks to push dictionary keys (names) or values (salaries) onto the stack.
- Examiner / Mentor Tip: Write clean function names matching the question prompt (e.g., `Push_Emp` and `Pop_Emp`) during the board exam.
7. Interactive Concept Check Quiz
Question: Given `D = {'E1': 49999, 'E2': 50000, 'E3': 50001, 'E4': 72000}`, if names with salary `> 50000` are pushed to a stack, which name is popped first?
8. Frequently Asked Questions
Should an employee earning exactly 50000 be pushed onto the stack?
Is it better to iterate with `.items()` or keys when filtering a dictionary?
How do I adapt this if the dictionary value is a list like `{'E1': ['Name', 60000]}`?
Explore Related Lessons & Free Interactive Tools
- All 110 Guides in CBSE CS (083) & IP (065) Hub
- CBSE 083 Board PYQ: Stack of Book Records & Hotel Customer Records
- Reverse a String and Sentence Words Using a Stack in Python
- Check Balanced Brackets Using a Python Stack
- Interactive Tool: CBSE CS 083 Python Output Predictor Quiz
- Interactive Tool: CBSE SQL GROUP BY / HAVING / JOIN Query Evaluator
