mirror of
https://github.com/McSmog/LeetCode-Questions-CompanyWise.git
synced 2026-04-19 08:46:45 +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)
```
10 lines
951 B
CSV
10 lines
951 B
CSV
ID,Title,Acceptance,Difficulty,Frequency,Leetcode Question Link
|
|
1359,Count All Valid Pickup and Delivery Options,57.9%,Hard,0.261487798668764, https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options
|
|
695,Max Area of Island,62.7%,Medium,0.22890365856149725, https://leetcode.com/problems/max-area-of-island
|
|
759,Employee Free Time,66.3%,Hard,0.16790196801661988, https://leetcode.com/problems/employee-free-time
|
|
1229,Meeting Scheduler,52.7%,Medium,0.09305870395398054, https://leetcode.com/problems/meeting-scheduler
|
|
37,Sudoku Solver,43.6%,Hard,0.01821543989134118, https://leetcode.com/problems/sudoku-solver
|
|
227,Basic Calculator II,36.9%,Medium,0.01239941490503826, https://leetcode.com/problems/basic-calculator-ii
|
|
56,Merge Intervals,39.3%,Medium,0.0034728286335985107, https://leetcode.com/problems/merge-intervals
|
|
210,Course Schedule II,40.7%,Medium,0.0019086707135282834, https://leetcode.com/problems/course-schedule-ii
|