Tenth Line — LeetCode 195 Python Solution
EasyShell
- Problem
- #195
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given a text file file.txt, print just the 10th line of the file.
Example
Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10
Python solution
Python
def print_tenth_line(path: str = "file.txt") -> None:
with open(path, "r", encoding="utf-8") as f:
for i, line in enumerate(f, 1):
if i == 10:
print(line.rstrip("\n"))
breakComplexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 195. Tenth Line?
- LeetCode 195. Tenth Line is rated Easy on LeetCode.
- What topics does LeetCode 195. Tenth Line cover?
- LeetCode 195. Tenth Line is tagged Shell on LeetCode.