# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14695 | Domo the employee |
|
14698 | A boring article |
|
Description
Our good friend Domo is an employee at a company that stores employee information in a CSV (comma-separated values) file. Each row represents one employee, and each column contains different details such as name, age, and city.
However, sometimes your friend only needs certain columns to create a smaller report (for example, only the name and city). Instead of doing this manually, they asked you to write a program that automatically extracts the requested columns from the CSV data.
You are given the CSV content as a string and a list of column indices to keep. Write a program to return a new CSV string that contains only the selected columns.
You may start with the given code
#TODO:
# Read the CSV input until EOF
csv_lines = []
while True:
try:
line = input()
if line.strip() == "":
continue
csv_lines.append(line)
except EOFError:
break
# First line = indices
ind_line = csv_lines[0]
ind = list(map(int, ind_line.split()))
# Remaining lines = CSV data
csv_str = "\n".join(csv_lines[1:])
# Process
print(extract_columns(csv_str, ind_line))
Please Submit the whole code, not only the functions
Input
-
The first line of the input contains the space-separated list of column indices to extract.
-
Followed by the CSV content, where:
-
Rows are separated by newline
\n
-
Columns are separated by commas
,
-
- The first row of the CSV is the header (column names)
Constraints
-
1 ≤ Number of rows ≤ 1000
-
1 ≤ Number of columns ≤ 50
-
Column indices are
0-based
and valid -
0 <= indices < Number of columns
To signal EOF you can use Ctrl + Z + Enter (Windows) or Ctrl + D (Linux/Mac)
Output
Output the CSV string containing only the selected columns, with rows preserved.
Output Format:
- Each column must be seperated by a comma (',')
- Each row of the output must end with a newline character ('\n')
- The very last line of your output should also end with exactly one newline ('\n')
- Do not add extra space at the end of any line
Sample Input Download
Sample Output Download
Discuss
Description
You are helping your friend who is writing an article. Sometimes, they feel their text is too repetitive because the same words appear again and again. To make it more interesting, your friend gives you a dictionary of synonyms.
Your task is to write a program that automatically replaces words with their synonyms whenever possible. If a word does not appear in the dictionary, it should remain unchanged.
Synonym Dictionary given
synonyms = {
"big": "large",
"small": "tiny",
"fast": "quick",
"slow": "sluggish",
"happy": "joyful",
"sad": "unhappy",
"angry": "furious",
"good": "great",
"bad": "awful",
"hot": "warm",
"cold": "chilly",
"smart": "clever",
"stupid": "dumb",
"easy": "simple",
"hard": "difficult",
"friend": "buddy",
"enemy": "foe",
"child": "kid",
"dog": "puppy",
"cat": "kitten"
}
Note
You should output the synonym as given in the dictionary (don't make you own synonym dictionary)
Input
-
A single line sentence (string).
-
Words are separated by spaces.
-
The input will not contain punctuation, tabs, or newlines — only words and spaces.
Output
-
A single line string where each word is replaced with its synonym (if found in the dictionary).
-
Case of the output word should follow the dictionary (always lowercase as defined).
-
If the word's synonym isn't found in the dictionary preserve it exactly as the input.
-
If the word is in the dictionary matching will be case-insensitive (e.g.,
Big
,BIG
, andbig
all map tolarge
). -
All spaces between words should be preserved exactly as in the input.
There should be '\n' at the end of the output