Python Easy technical 0 views 1 min read

Print the index of a specific item in a list?

Peer-reviewed by HireXTech Technical Panel • Updated for 2025/2026 hiring • Editorial standards
Practise this track
Interviewer Expectations for this Question
01
Core Competency

Assesses fundamental understanding of Python conventions, runtime behavior, and memory/performance considerations.

02
Evaluation Criteria

Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.

Comprehensive Model Answer Verified Solution

In Python, you find the index of an element in a list using the list.index() method:

technologies = ['React', 'Python', 'Docker', 'PostgreSQL']

# Finding the index
idx = technologies.index('Docker')
print(f"Index of Docker: {idx}")  # Output: Index of Docker: 2

### Handling Missing Items Safely:
If the item does not exist in the list, list.index() raises a ValueError. Prevent crashes using in check or try/except:

search_target = 'GraphQL'

if search_target in technologies:
    print(technologies.index(search_target))
else:
    print(f"'{search_target}' not found in list.")

### Enumerating While Iterating:
To print both the index and value during iteration, use the built-in enumerate() function:

for idx, tech in enumerate(technologies):
    print(f"#{idx}: {tech}")

Candidate Response Strategy & Interview Tips

  1. Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
  2. Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
  3. Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
  4. Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.
Related Topics & Skills
Spotted an error or have an alternative solution?