mirror of
https://github.com/krishnadey30/LeetCode-Questions-CompanyWise.git
synced 2025-12-28 05:34:42 +00:00
## Description
- Add headers to all the CSV files
## Script used
```py
import csv
import os
# Set the path of the folder containing the CSV files
folder_path = "./LeetCode-Questions-CompanyWise"
headers = [
"ID",
"Title",
"Acceptance",
"Difficulty",
"Frequency",
"Leetcode Question Link",
]
# Loop through all the CSV files in the folder
for file_name in os.listdir(folder_path):
if file_name.endswith(".csv"):
# Read the CSV file into a list of rows
file_path = os.path.join(folder_path, file_name)
with open(file_path, "r") as f:
reader = csv.reader(f)
rows = list(reader)
has_headers = False
if len(rows) > 0 and rows[0] == headers:
has_headers = True
if not has_headers:
rows.insert(0, headers)
# Write the list of rows back to the CSV file
with open(file_path, "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(rows)
```
691 B
691 B
| 1 | ID | Title | Acceptance | Difficulty | Frequency | Leetcode Question Link |
|---|---|---|---|---|---|---|
| 2 | 509 | Fibonacci Number | 67.2% | Easy | 0.03801871583399193 | https://leetcode.com/problems/fibonacci-number |
| 3 | 115 | Distinct Subsequences | 38.3% | Hard | 0.027798871362742988 | https://leetcode.com/problems/distinct-subsequences |
| 4 | 20 | Valid Parentheses | 39.0% | Easy | 0.020517047266669974 | https://leetcode.com/problems/valid-parentheses |
| 5 | 91 | Decode Ways | 24.7% | Medium | 0.013379120336324091 | https://leetcode.com/problems/decode-ways |
| 6 | 273 | Integer to English Words | 27.1% | Hard | 0.012081089250339716 | https://leetcode.com/problems/integer-to-english-words |
| 7 | 7 | Reverse Integer | 25.8% | Easy | 0.0018612447790907708 | https://leetcode.com/problems/reverse-integer |