From 776b2d8fbdbee55fa15c9cd8ee33ce97339b2fc4 Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Mon, 6 Jan 2025 20:35:35 +0530 Subject: [PATCH 1/9] Added problem-solving question: Marks Aggregator by Chandan --- .../problem_solving_question.proq | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 questions_by_Chandan/problem_solving_question.proq diff --git a/questions_by_Chandan/problem_solving_question.proq b/questions_by_Chandan/problem_solving_question.proq new file mode 100644 index 0000000..9b7ebec --- /dev/null +++ b/questions_by_Chandan/problem_solving_question.proq @@ -0,0 +1,24 @@ +Problem Statement: +Write a function `find_highest_scorer(scores)` that takes a dictionary `scores` where keys are student names and values are their scores. The function should return the name of the student with the highest score. If there is a tie, return the name that comes first alphabetically. + +Solution: +def find_highest_scorer(scores): + if not scores: + return None + max_score = max(scores.values()) + highest_scorers = [name for name, score in scores.items() if score == max_score] + return sorted(highest_scorers)[0] + +Public Test Cases: +Input: {'Alice': 85, 'Bob': 90, 'Charlie': 90} +Output: 'Bob' + +Input: {} +Output: None + +Private Test Cases: +Input: {'David': 95, 'Eva': 85, 'Frank': 95} +Output: 'David' + +Input: {'Anna': 100} +Output: 'Anna' \ No newline at end of file From 48a9110e9cde44a36c49d7cb0c93819f214af571 Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Mon, 6 Jan 2025 21:24:17 +0530 Subject: [PATCH 2/9] Added problem-solving question: Marks Aggregator by Chandan --- .../problem_solving_question.proq | 96 ++++++++++++++----- 1 file changed, 72 insertions(+), 24 deletions(-) diff --git a/questions_by_Chandan/problem_solving_question.proq b/questions_by_Chandan/problem_solving_question.proq index 9b7ebec..2f3a2fe 100644 --- a/questions_by_Chandan/problem_solving_question.proq +++ b/questions_by_Chandan/problem_solving_question.proq @@ -1,24 +1,72 @@ -Problem Statement: -Write a function `find_highest_scorer(scores)` that takes a dictionary `scores` where keys are student names and values are their scores. The function should return the name of the student with the highest score. If there is a tie, return the name that comes first alphabetically. - -Solution: -def find_highest_scorer(scores): - if not scores: - return None - max_score = max(scores.values()) - highest_scorers = [name for name, score in scores.items() if score == max_score] - return sorted(highest_scorers)[0] - -Public Test Cases: -Input: {'Alice': 85, 'Bob': 90, 'Charlie': 90} -Output: 'Bob' - -Input: {} -Output: None - -Private Test Cases: -Input: {'David': 95, 'Eva': 85, 'Frank': 95} -Output: 'David' - -Input: {'Anna': 100} -Output: 'Anna' \ No newline at end of file +--- +title: Manipulate Data +tags: ['array','sorting'] +--- + +# Problem Statement + +Given a dictionary d with keys of data structures int , float, set , list and str. +Modify the given data structures in the dict using an function process_data as following: +1. int -> Do an square of the given integer +2. float -> trunicate the float +3. str -> Reverse the string +4. list -> Convert it into the sum of all integers in list +5. set -> Find the max element in the set and replace it as value + +# Solution + +py3 test.py -r 'python test.py' + + +{% include './function_type_and_modify_check_suffix.py.jinja' %} + + + +# Public Test Cases + +## Input 1 + + +d = {'int' : 2 , 'float' : 8.2 , 'str' : "hem" , 'list' : [1,2,4,5] , 'set' : {1,8,9} } +is_equal( +process_data(d), +{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } +) + + +## Output 1 + + +{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } + + +# Private Test Cases + +## Input 1 + + +d = {'int' : 2 , 'float' : 8.2 , 'str' : "hem" , 'list' : [1,2,4,5] , 'set' : {1,8,9} } +is_equal( +process_data(d), +{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } +) + + +## Output 1 + + +{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } + + + From 9d88705f0c1f417ee2cb405e98be54077f6f91fe Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Mon, 6 Jan 2025 21:35:06 +0530 Subject: [PATCH 3/9] Removed problem_solving_question.proq from questions_by_Chandan --- .../problem_solving_question.proq | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 questions_by_Chandan/problem_solving_question.proq diff --git a/questions_by_Chandan/problem_solving_question.proq b/questions_by_Chandan/problem_solving_question.proq deleted file mode 100644 index 2f3a2fe..0000000 --- a/questions_by_Chandan/problem_solving_question.proq +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: Manipulate Data -tags: ['array','sorting'] ---- - -# Problem Statement - -Given a dictionary d with keys of data structures int , float, set , list and str. -Modify the given data structures in the dict using an function process_data as following: -1. int -> Do an square of the given integer -2. float -> trunicate the float -3. str -> Reverse the string -4. list -> Convert it into the sum of all integers in list -5. set -> Find the max element in the set and replace it as value - -# Solution - -py3 test.py -r 'python test.py' - - -{% include './function_type_and_modify_check_suffix.py.jinja' %} - - - -# Public Test Cases - -## Input 1 - - -d = {'int' : 2 , 'float' : 8.2 , 'str' : "hem" , 'list' : [1,2,4,5] , 'set' : {1,8,9} } -is_equal( -process_data(d), -{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } -) - - -## Output 1 - - -{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } - - -# Private Test Cases - -## Input 1 - - -d = {'int' : 2 , 'float' : 8.2 , 'str' : "hem" , 'list' : [1,2,4,5] , 'set' : {1,8,9} } -is_equal( -process_data(d), -{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } -) - - -## Output 1 - - -{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } - - - From e48b904c9f6f236c6e828e481c1148870ad25b75 Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Mon, 6 Jan 2025 21:42:09 +0530 Subject: [PATCH 4/9] Added problem-solving question: Manipulate Data by Chandan --- .../problem_solving_question.proq | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 questions_by_Chandan/problem_solving_question.proq diff --git a/questions_by_Chandan/problem_solving_question.proq b/questions_by_Chandan/problem_solving_question.proq new file mode 100644 index 0000000..2f3a2fe --- /dev/null +++ b/questions_by_Chandan/problem_solving_question.proq @@ -0,0 +1,72 @@ +--- +title: Manipulate Data +tags: ['array','sorting'] +--- + +# Problem Statement + +Given a dictionary d with keys of data structures int , float, set , list and str. +Modify the given data structures in the dict using an function process_data as following: +1. int -> Do an square of the given integer +2. float -> trunicate the float +3. str -> Reverse the string +4. list -> Convert it into the sum of all integers in list +5. set -> Find the max element in the set and replace it as value + +# Solution + +py3 test.py -r 'python test.py' + + +{% include './function_type_and_modify_check_suffix.py.jinja' %} + + + +# Public Test Cases + +## Input 1 + + +d = {'int' : 2 , 'float' : 8.2 , 'str' : "hem" , 'list' : [1,2,4,5] , 'set' : {1,8,9} } +is_equal( +process_data(d), +{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } +) + + +## Output 1 + + +{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } + + +# Private Test Cases + +## Input 1 + + +d = {'int' : 2 , 'float' : 8.2 , 'str' : "hem" , 'list' : [1,2,4,5] , 'set' : {1,8,9} } +is_equal( +process_data(d), +{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } +) + + +## Output 1 + + +{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } + + + From 29ddf9456f8471aa8decc36af73979a7f6f3f400 Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Tue, 7 Jan 2025 10:41:24 +0530 Subject: [PATCH 5/9] Added problem: Squaring a number by Chandan --- questions_by_Chandan/test.proq | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 questions_by_Chandan/test.proq diff --git a/questions_by_Chandan/test.proq b/questions_by_Chandan/test.proq new file mode 100644 index 0000000..b11491a --- /dev/null +++ b/questions_by_Chandan/test.proq @@ -0,0 +1,15 @@ +--- +title: Test Question +tags: ['basic'] +--- +# Problem Statement +Given a number, return its square. +# Solution + +# Public Test Cases +## Input 1 +n = 4 +is_equal(square(n), 16) \ No newline at end of file From a3c19c7f1bd904a249103efd47142623a1fc270e Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Tue, 7 Jan 2025 11:02:26 +0530 Subject: [PATCH 6/9] Remove test.proq --- .../data_processing_io_question.proq | 0 .../data_processing_question.proq | 0 questions_by_Chandan/data_types_question.proq | 0 .../problem_solving_question.proq | 54 ++++++------------- questions_by_Chandan/test.proq | 15 ------ 5 files changed, 17 insertions(+), 52 deletions(-) create mode 100644 questions_by_Chandan/data_processing_io_question.proq create mode 100644 questions_by_Chandan/data_processing_question.proq create mode 100644 questions_by_Chandan/data_types_question.proq delete mode 100644 questions_by_Chandan/test.proq diff --git a/questions_by_Chandan/data_processing_io_question.proq b/questions_by_Chandan/data_processing_io_question.proq new file mode 100644 index 0000000..e69de29 diff --git a/questions_by_Chandan/data_processing_question.proq b/questions_by_Chandan/data_processing_question.proq new file mode 100644 index 0000000..e69de29 diff --git a/questions_by_Chandan/data_types_question.proq b/questions_by_Chandan/data_types_question.proq new file mode 100644 index 0000000..e69de29 diff --git a/questions_by_Chandan/problem_solving_question.proq b/questions_by_Chandan/problem_solving_question.proq index 2f3a2fe..74e6489 100644 --- a/questions_by_Chandan/problem_solving_question.proq +++ b/questions_by_Chandan/problem_solving_question.proq @@ -1,23 +1,22 @@ --- title: Manipulate Data -tags: ['array','sorting'] +tags: ['array', 'sorting'] --- # Problem Statement -Given a dictionary d with keys of data structures int , float, set , list and str. -Modify the given data structures in the dict using an function process_data as following: -1. int -> Do an square of the given integer -2. float -> trunicate the float -3. str -> Reverse the string -4. list -> Convert it into the sum of all integers in list -5. set -> Find the max element in the set and replace it as value +Given a dictionary `d` with keys of data structures `int`, `float`, `set`, `list`, and `str`. +Modify the given data structures in the dictionary using a function `process_data` as follows: +1. `int` -> Square the given integer. +2. `float` -> Truncate the float. +3. `str` -> Reverse the string. +4. `list` -> Replace it with the sum of all integers in the list. +5. `set` -> Replace it with the maximum element in the set. # Solution -py3 test.py -r 'python test.py' - -{% include './function_type_and_modify_check_suffix.py.jinja' %} - - # Public Test Cases ## Input 1 - - -d = {'int' : 2 , 'float' : 8.2 , 'str' : "hem" , 'list' : [1,2,4,5] , 'set' : {1,8,9} } +d = {'int': 2, 'float': 8.2, 'str': "hem", 'list': [1, 2, 4, 5], 'set': {1, 8, 9}} is_equal( -process_data(d), -{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } + process_data(d), + {'int': 4, 'float': 8, 'str': "meh", 'list': 12, 'set': 9} ) - ## Output 1 - - -{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } - +{'int': 4, 'float': 8, 'str': "meh", 'list': 12, 'set': 9} # Private Test Cases ## Input 1 - - -d = {'int' : 2 , 'float' : 8.2 , 'str' : "hem" , 'list' : [1,2,4,5] , 'set' : {1,8,9} } +d = {'int': 5, 'float': 12.7, 'str': "chat", 'list': [10, 20, 30], 'set': {10, 50, 40}} is_equal( -process_data(d), -{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } + process_data(d), + {'int': 25, 'float': 12, 'str': "tahc", 'list': 60, 'set': 50} ) - ## Output 1 - - -{'int' : 4 , 'float' : 8 , 'str' : "meh" , 'list' : 12 , 'set' : 9 } - - - +{'int': 25, 'float': 12, 'str': "tahc", 'list': 60, 'set': 50} diff --git a/questions_by_Chandan/test.proq b/questions_by_Chandan/test.proq deleted file mode 100644 index b11491a..0000000 --- a/questions_by_Chandan/test.proq +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: Test Question -tags: ['basic'] ---- -# Problem Statement -Given a number, return its square. -# Solution - -# Public Test Cases -## Input 1 -n = 4 -is_equal(square(n), 16) \ No newline at end of file From df47d9fde1387243b175032674cd3dca5075c53b Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Tue, 7 Jan 2025 11:13:32 +0530 Subject: [PATCH 7/9] Added problem-solving question: Manipulation of Data by Chandan --- questions_by_Chandan/problem_solving_question.proq | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/questions_by_Chandan/problem_solving_question.proq b/questions_by_Chandan/problem_solving_question.proq index 74e6489..985dba5 100644 --- a/questions_by_Chandan/problem_solving_question.proq +++ b/questions_by_Chandan/problem_solving_question.proq @@ -15,6 +15,10 @@ Modify the given data structures in the dictionary using a function `process_dat # Solution +```py3 test.py -r 'python test.py' + +# some prefix + + +# some suffix + + +{% include '../function_type_and_modify_check_suffix.py.jinja' %} + +``` # Public Test Cases From d565f1b890925327c0d610b6aec86eb5433f0ec0 Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Tue, 7 Jan 2025 16:55:09 +0530 Subject: [PATCH 8/9] Removed problem_solving_question.proq from questions_by_Chandan --- .../problem_solving_question.proq | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 questions_by_Chandan/problem_solving_question.proq diff --git a/questions_by_Chandan/problem_solving_question.proq b/questions_by_Chandan/problem_solving_question.proq deleted file mode 100644 index 985dba5..0000000 --- a/questions_by_Chandan/problem_solving_question.proq +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: Manipulate Data -tags: ['array', 'sorting'] ---- - -# Problem Statement - -Given a dictionary `d` with keys of data structures `int`, `float`, `set`, `list`, and `str`. -Modify the given data structures in the dictionary using a function `process_data` as follows: -1. `int` -> Square the given integer. -2. `float` -> Truncate the float. -3. `str` -> Reverse the string. -4. `list` -> Replace it with the sum of all integers in the list. -5. `set` -> Replace it with the maximum element in the set. - -# Solution - -```py3 test.py -r 'python test.py' - -# some prefix - - - -# some suffix - - -{% include '../function_type_and_modify_check_suffix.py.jinja' %} - -``` - -# Public Test Cases - -## Input 1 -d = {'int': 2, 'float': 8.2, 'str': "hem", 'list': [1, 2, 4, 5], 'set': {1, 8, 9}} -is_equal( - process_data(d), - {'int': 4, 'float': 8, 'str': "meh", 'list': 12, 'set': 9} -) - -## Output 1 -{'int': 4, 'float': 8, 'str': "meh", 'list': 12, 'set': 9} - -# Private Test Cases - -## Input 1 -d = {'int': 5, 'float': 12.7, 'str': "chat", 'list': [10, 20, 30], 'set': {10, 50, 40}} -is_equal( - process_data(d), - {'int': 25, 'float': 12, 'str': "tahc", 'list': 60, 'set': 50} -) - -## Output 1 -{'int': 25, 'float': 12, 'str': "tahc", 'list': 60, 'set': 50} From 0cae557ea5c7b4655c93b34e51cb4e8232af6bae Mon Sep 17 00:00:00 2001 From: Chandan Kumar <23f1003124@ds.study.iitm.ac.in> Date: Wed, 8 Jan 2025 23:32:37 +0530 Subject: [PATCH 9/9] Questions by Chandan --- questions_by_Chandan/Data_processing2.md | 272 ++++++++++++++ questions_by_Chandan/Data_processing_io.md | 227 ++++++++++++ questions_by_Chandan/Data_type1.md | 340 ++++++++++++++++++ questions_by_Chandan/Problem_solving.md | 173 +++++++++ .../data_processing_io_question.proq | 0 .../data_processing_question.proq | 0 questions_by_Chandan/data_types_question.proq | 0 7 files changed, 1012 insertions(+) create mode 100644 questions_by_Chandan/Data_processing2.md create mode 100644 questions_by_Chandan/Data_processing_io.md create mode 100644 questions_by_Chandan/Data_type1.md create mode 100644 questions_by_Chandan/Problem_solving.md delete mode 100644 questions_by_Chandan/data_processing_io_question.proq delete mode 100644 questions_by_Chandan/data_processing_question.proq delete mode 100644 questions_by_Chandan/data_types_question.proq diff --git a/questions_by_Chandan/Data_processing2.md b/questions_by_Chandan/Data_processing2.md new file mode 100644 index 0000000..a87384a --- /dev/null +++ b/questions_by_Chandan/Data_processing2.md @@ -0,0 +1,272 @@ +--- +title: Basic Data Processing +tags: [mapping, filter aggragation, sorting, grouping, Basic Data Processing] +--- + +# Problem Statement + +--- + +You need to implement the following functions: + +1. **square_numbers(d)** + - Description: Given a list 'd' of numbers, returns a new list with each number squared. + - Example: + + ```python + square_numbers([1,2,3,4,5]) # Output: [1,4,9,16,25] + square_numbers([-1,0,-3,5,2]) # Output: [1,0,9,25,4] + ``` + + +2. **filter_aggregation(d, k)** + - Description: Given a list 'd' of numbers and threshold, returns the sum of numbers greater than or equal to the given threshold. + - Example: + + ```python + filter_even_numbers([3,6,10,23,16], 10) # Output: 49 + filter_even_numbers([1,2,3,45,6], 6) # Output: 51 + ``` + +3. **`sort_strings(d)`** + - Description: Given a list 'd' of strings, return a new list with strings sorted alphabetically. + - Example: + ```python + sort_strings(['Rohan', 'Sohan', 'Bharath']) # Output: ['Bharath', 'Rohan', 'Sohan'] + sorti_strings(['Elizabeth', 'Sudharshini', 'Nanditha']) # Output: ['Elizabeth', Nanditha', Sudharshini'] + ``` + +4. **group_by_key(d)** + - Description: Given a list 'd' of tuples(key, value), returns a dictionary where keys map to list of values. + - Example: + + ```python + group_by_key([("fruit", "apple"), ("fruit", "banana"), ("veg", "carrot")]) # Output: {'fruit': ['apple', 'banana'], 'veg':['carrort']} + group_by_key([("electronics", "smartphone"),("clothing", "t-shirt"),("electronics", "laptop"),("clothing", "jeans"),("grocery", "milk")]) + # Output : {'electronics':['smartphone', 'laptop'], 'clothing': ['t-shirt', 'jean'], 'grocery':['milk']} + ``` + +# Solution +```py3 test.py -r 'python test.py' + + + + + +{% include '../function_type_and_modify_check_suffix.py.jinja' %} + +``` +# Public Test Cases + +## Input 1 + +``` +d = [1,2,3,4] +is_equal( + square_numbers(d), + [1,4,9,16] +) + +d = [23, 14, 7, 8, 5] +threshold = 8 +is_equal( + filter_aggregation(d, threshold), + 45 +) + +d = ['Bharath', 'Kavya', 'Sudharshini', 'David'] +is_equal( + sort_strings(d), + ['Bharath', 'David', 'Kavya', 'Sudharshini'] +) + +d = [("fruit", "apple"), ("fruit", "banana"), ("veg", "carrot")] +is_equal( + group_by_key(d), + {'fruit':['apple', 'banana'], 'veg':['carrot']} +) +``` +## Output 1 +``` +[1, 4, 9, 16] +45 +['Bharath', 'David', 'Kavya', 'Sudharshini'] +{'fruit': ['apple', 'banana'], 'veg': ['carrot']} +``` +## Input 2 + +``` +d = [5, 6, 7, 8] +is_equal( + square_numbers(d), + [25, 36, 49, 64] +) + +d = [12, 5, 9, 7, 3] +threshold = 9 +is_equal( + filter_aggregation(d, threshold), + 21 +) + +d = ['Zara', 'Alex', 'Chandan', 'Meera'] +is_equal( + sort_strings(d), + ['Alex', 'Chandan', 'Meera', 'Zara'] +) + +d = [("animal", "cat"), ("animal", "dog"), ("bird", "parrot")] +is_equal( + group_by_key(d), + {'animal': ['cat', 'dog'], 'bird': ['parrot']} +) +``` +## Output 2 +``` +[25, 36, 49, 64] +21 +['Alex', 'Chandan', 'Meera', 'Zara'] +{'animal': ['cat', 'dog'], 'bird': ['parrot']} +``` + +## Input 3 +``` +d = [10, 11, 12, 13] +is_equal( + square_numbers(d), + [100, 121, 144, 169] +) + +d = [18, 15, 7, 3, 2] +threshold = 10 +is_equal( + filter_aggregation(d, threshold), + 33 +) + +d = ['Ananya', 'Vikas', 'Sameer', 'Esha'] +is_equal( + sort_strings(d), + ['Ananya', 'Esha', 'Sameer', 'Vikas'] +) + +d = [("color", "red"), ("color", "blue"), ("shape", "circle")] +is_equal( + group_by_key(d), + {'color': ['red', 'blue'], 'shape': ['circle']} +) +``` +## Output 3 + +``` +[100, 121, 144, 169] +33 +['Ananya', 'Esha', 'Sameer', 'Vikas'] +{'color': ['red', 'blue'], 'shape': ['circle']} +``` + +# Private Test Cases + +## Input 1 + +``` +d = [2, 4, 6, 8] +is_equal( + square_numbers(d), + [4, 16, 36, 64] +) + +d = [25, 18, 10, 7, 3] +threshold = 15 +is_equal( + filter_aggregation(d, threshold), + 43 +) + +d = ['Ravi', 'Suresh', 'Neha', 'Alok'] +is_equal( + sort_strings(d), + ['Alok', 'Neha', 'Ravi', 'Suresh'] +) + +d = [("city", "Delhi"), ("city", "Mumbai"), ("country", "India")] +is_equal( + group_by_key(d), + {'city': ['Delhi', 'Mumbai'], 'country': ['India']} +) +``` +## Output 1 +``` +[4, 16, 36, 64] +43 +['Alok', 'Neha', 'Ravi', 'Suresh'] +{'city': ['Delhi', 'Mumbai'], 'country': ['India']} +``` \ No newline at end of file diff --git a/questions_by_Chandan/Data_processing_io.md b/questions_by_Chandan/Data_processing_io.md new file mode 100644 index 0000000..031f384 --- /dev/null +++ b/questions_by_Chandan/Data_processing_io.md @@ -0,0 +1,227 @@ +--- +title: Data Processing I/O +tags: [mapping, filtering, aggregation, sorting, grouping, I/O] +--- + +# Problem Statement + +You need to implement the following functions. These functions should read inputs from stdin and write the output to stdout in the specified format. + +1. **`sum_even_numbers(d)`** + - Description: Given a list of numbers, sum all the even numbers and print the result to stdout. + - Input: A list of integers `d`. + - Output: Print the sum of all even numbers in the list. + - Example: + ```python + sum_even_numbers([1, 2, 3, 4, 5]) # Output: 6 + sum_even_numbers([10, 21, 34, 50]) # Output: 94 + ``` + +2. **`filter_greater_than_threshold(d, threshold)`** + - Description: Given a list of numbers and a threshold, filter out the numbers greater than or equal to the threshold and print them to stdout. + - Input: A list of integers `d` and an integer `threshold`. + - Output: Print the filtered list. + - Example: + ```python + filter_greater_than_threshold([1, 2, 3, 4, 5], 3) # Output: [3, 4, 5] + filter_greater_than_threshold([10, 20, 30], 15) # Output: [20, 30] + ``` + +3. **`sort_and_print(d)`** + - Description: Given a list of strings, sort them alphabetically and print the sorted list to stdout. + - Input: A list of strings `d`. + - Output: Print the sorted list. + - Example: + ```python + sort_and_print(["banana", "apple", "cherry"]) # Output: ['apple', 'banana', 'cherry'] + sort_and_print(["mango", "kiwi", "apple"]) # Output: ['apple', 'kiwi', 'mango'] + ``` + +4. **`group_by_category(d)`** + - Description: Given a list of tuples (category, item), group the items by category and print the grouped dictionary to stdout. + - Input: A list of tuples `d`, where each tuple contains a category and an item. + - Output: Print the dictionary with categories as keys and lists of items as values. + - Example: + ```python + group_by_category([("fruit", "apple"), ("fruit", "banana"), ("veg", "carrot")]) + # Output: {'fruit': ['apple', 'banana'], 'veg': ['carrot']} + + group_by_category([("animal", "cat"), ("animal", "dog"), ("bird", "sparrow")]) + # Output: {'animal': ['cat', 'dog'], 'bird': ['sparrow']} + ``` + +# Solution + +```py3 test.py -r 'python test.py' + + + + + +{% include '../function_type_and_modify_check_suffix.py.jinja' %} + +``` + +# Public Test Cases + +## Input 1 +``` + +d = [1, 2, 3, 4, 5] +is_equal( + sum_even_numbers(d), + 6 +) + +d = [1, 2, 3, 4, 5] +threshold = 3 +is_equal( + filter_greater_than_threshold(d, threshold), + [3, 4, 5] +) + +d = ['apple', 'banana', 'cherry'] +is_equal( + sort_and_print(d), + ['apple', 'banana', 'cherry'] +) + +d = [("fruit", "apple"), ("fruit", "banana"), ("veg", "carrot")] +is_equal( + group_by_category(d), + {'fruit': ['apple', 'banana'], 'veg': ['carrot']} +) + +``` + +## Output 1 + +``` +6 +[3, 4, 5] +['apple', 'banana', 'cherry'] +{'fruit': ['apple', 'banana'], 'veg': ['carrot']} + +``` + +## Input 2 + +``` +d = [10, 21, 34, 50] +is_equal( + sum_even_numbers(d), + 94 +) + +d = [5, 6, 7, 8] +threshold = 6 +is_equal( + filter_greater_than_threshold(d, threshold), + [6, 7, 8] +) + +d = ['mango', 'kiwi', 'apple'] +is_equal( + sort_and_print(d), + ['apple', 'kiwi', 'mango'] +) + +d = [("animal", "cat"), ("animal", "dog"), ("bird", "sparrow")] +is_equal( + group_by_category(d), + {'animal': ['cat', 'dog'], 'bird': ['sparrow']} +) + +``` + +## Output 2 + +``` +94 +[6, 7, 8] +['apple', 'kiwi', 'mango'] +{'animal': ['cat', 'dog'], 'bird': ['sparrow']} + +``` + +# Private Test Cases + + +## Input 1 + +``` + +d = [12, 14, 16, 18] +is_equal( + sum_even_numbers(d), + 60 +) + +d = [30, 40, 50] +threshold = 35 +is_equal( + filter_greater_than_threshold(d, threshold), + [40, 50] +) + +d = ['zebra', 'elephant', 'tiger'] +is_equal( + sort_and_print(d), + ['elephant', 'tiger', 'zebra'] +) + +d = [("fruit", "mango"), ("veg", "carrot"), ("fruit", "apple")] +is_equal( + group_by_category(d), + {'fruit': ['mango', 'apple'], 'veg': ['carrot']} +) + +``` + +## Output 1 + +``` +60 +[40, 50] +['elephant', 'tiger', 'zebra'] +{'fruit': ['mango', 'apple'], 'veg': ['carrot']} + +``` + diff --git a/questions_by_Chandan/Data_type1.md b/questions_by_Chandan/Data_type1.md new file mode 100644 index 0000000..27374f8 --- /dev/null +++ b/questions_by_Chandan/Data_type1.md @@ -0,0 +1,340 @@ +--- +title: Basic Data types +tags: [truncation,float,string_functions,type_checking,Basic Data Types] +--- + +# Problem Statement + +--- + +You need to implement the following functions: + +1. **`float_truncate(d)`** + - Description: This function accepts a float and truncates it to an integer, then returns the result. + - Example: + ```python + float_truncate(10.9) # Output: 10 + float_truncate(-5.7) # Output: -5 + ``` + +2. **`is_it_integer(d)`** + - Description: This function accepts any data type and returns a boolean indicating whether the input is an integer. + - Example: + ```python + is_it_integer(5) # Output: True + is_it_integer("Hello") # Output: False + is_it_integer(3.14) # Output: False + ``` + +3. **`Reverse_str(s)`** + - Description: This function accepts a string and returns the reversed version of the string. You should not use loops to achieve this. + - Example: + ```python + Reverse_str("hello") # Output: "olleh" + Reverse_str("Python") # Output: "nohtyP" + ``` + +4. **`Max_set(s)`** + - Description: This function accepts a set `s` and returns the maximum element from the set. + - Example: + ```python + Max_set({1, 2, 3, 4}) # Output: 4 + Max_set({-10, -5, -1}) # Output: -1 + ``` + +5. **`List_sum(l)`** + - Description: This function accepts a list `l` and returns the sum of all elements in the list. You should not use loops. + - Example: + ```python + List_sum([1, 2, 3]) # Output: 6 + List_sum([10, -5, 7]) # Output: 12 + ``` + +6. **`Dict_keys_find(d)`** + - Description: This function accepts a dictionary `d` and returns a list of all the keys in the dictionary. + - Example: + ```python + Dict_keys_find({"a": 1, "b": 2}) # Output: ["a", "b"] + Dict_keys_find({"name": "Alice", "age": 25}) # Output: ["name", "age"] + ``` + +# Solution + +```py3 test.py -r 'python test.py' + + + + + +{% include '../function_type_and_modify_check_suffix.py.jinja' %} + +``` + +# Public Test Cases + +## Input 1 + +``` +d = 7.6 +is_equal( + float_truncate(d), + 7 +) + +d = "Hello" +is_equal( + is_it_integer(d), + False +) + +is_equal( + Reverse_str("Python"), + 'nohtyP' +) + +s = {1, 2, 3, 4} +is_equal( + Max_set(s), + 4 +) + +l = [1, 2, 3, 4] +is_equal( + List_sum(l), + 10 +) + +d = {"name": "Alice", "age": 25} +is_equal( + Dict_keys_find(d), + ['name', 'age'] +) + +``` + +## Output 1 + +``` +7 +False +'nohtyP' +4 +10 +['name', 'age'] + +``` + +## Input 2 + +``` +d = 3.14 +is_equal( + float_truncate(d), + 3 +) + +d = 5 +is_equal( + is_it_integer(d), + True +) + +is_equal( + Reverse_str("world"), + 'dlrow' +) + +s = {10, 20, 30} +is_equal( + Max_set(s), + 30 +) + +is_equal( + List_sum([5, 10, 15]), + 30 +) + +d = {"name": "Alice", "age": 25} +is_equal( + Dict_keys_find(d), + ['name', 'age'] +) + +``` + +## Output 2 + +``` +3 +True +'dlrow' +30 +30 +['name', 'age'] + +``` + +## Input 3 + +``` +d = 16.9 +is_equal( + float_truncate(d), + 16 +) + +d = [1, 2, 3] +is_equal( + is_it_integer(d), + False +) + +is_equal( + List_sum([5, 10, 15]), + 30 +) + +d = {"fruit": "apple", "color": "red"} +is_equal( + Dict_keys_find(d), + ['fruit', 'color'] +) + +``` + +## Output 3 + +``` +16 +False +30 +['fruit', 'color'] + +``` + +# Private Test Cases + +## Input 1 + +``` +d = 8.2 +is_equal( + float_truncate(d), + 8 +) + +d = 'Python' +is_equal( + is_it_integer(d), + False +) + +is_equal( + List_sum([10,20,30,40,50]), + 150 +) + +is_equal( + Max_set({1,2,3,4,5}), + 5 +) + +is_equal( + Reverse_str('Amit'), + 'timA' +) + +d = {'one':1, 'two':2, 'three': 3} +is_equal( + Dict_keys_find(d), + ['one', 'two', 'three'] +) + +``` + + +## Output 1 + +``` +8 +False +150 +5 +'timA' +['one', 'two', 'three'] + +``` \ No newline at end of file diff --git a/questions_by_Chandan/Problem_solving.md b/questions_by_Chandan/Problem_solving.md new file mode 100644 index 0000000..fa7bdf7 --- /dev/null +++ b/questions_by_Chandan/Problem_solving.md @@ -0,0 +1,173 @@ +--- +title: Order Management System +tags: [application, problem-solving, functions, dictionary, list] +--- + +# Problem Statement + +--- + +You are tasked to develop an **Order Management System** for a small business. Implement the following functions: + +1. **`add_order(order_list, order_id, product, quantity)`** + - Description: Adds a new order to the `order_list`. + - Arguments: + - `order_list` (list): A list where each order is a dictionary. + - `order_id` (int): Unique ID for the order. + - `product` (str): Name of the product ordered. + - `quantity` (int): Quantity of the product ordered. + - Returns: Updated `order_list`. + - Example: + ```python + add_order([], 101, 'Apple', 5) + # Output: [{'order_id': 101, 'product': 'Apple', 'quantity': 5}] + ``` + +2. **`update_order(order_list, order_id, new_quantity)`** + - Description: Updates the quantity of an existing order. If the order ID is not found, return "Order not found". + - Arguments: + - `order_list` (list): List of orders. + - `order_id` (int): ID of the order to update. + - `new_quantity` (int): Updated quantity for the order. + - Returns: Updated `order_list` or an error message. + - Example: + ```python + update_order([{'order_id': 101, 'product': 'Apple', 'quantity': 5}], 101, 10) + # Output: [{'order_id': 101, 'product': 'Apple', 'quantity': 10}] + ``` + +3. **`delete_order(order_list, order_id)`** + - Description: Deletes an order from the `order_list` based on the order ID. If the order ID is not found, return "Order not found". + - Arguments: + - `order_list` (list): List of orders. + - `order_id` (int): ID of the order to delete. + - Returns: Updated `order_list` or an error message. + - Example: + ```python + delete_order([{'order_id': 101, 'product': 'Apple', 'quantity': 5}], 101) + # Output: [] + ``` + +4. **`get_order_summary(order_list)`** + - Description: Returns a summary of all orders, grouped by product, showing the total quantity for each product. + - Arguments: + - `order_list` (list): List of orders. + - Returns: A dictionary where keys are product names, and values are the total quantities. + - Example: + ```python + get_order_summary([{'order_id': 101, 'product': 'Apple', 'quantity': 5}, {'order_id': 102, 'product': 'Apple', 'quantity': 3}, {'order_id': 103, 'product': 'Banana', 'quantity': 2}]) + # Output: {'Apple': 8, 'Banana': 2} + ``` + +--- + +# Solution + +```python +def add_order(order_list, order_id, product, quantity): + order_list.append({'order_id': order_id, 'product': product, 'quantity': quantity}) + return order_list + +def update_order(order_list, order_id, new_quantity): + for order in order_list: + if order['order_id'] == order_id: + order['quantity'] = new_quantity + return order_list + return "Order not found" + +def delete_order(order_list, order_id): + for order in order_list: + if order['order_id'] == order_id: + order_list.remove(order) + return order_list + return "Order not found" + +def get_order_summary(order_list): + summary = {} + for order in order_list: + product = order['product'] + quantity = order['quantity'] + if product in summary: + summary[product] += quantity + else: + summary[product] = quantity + return summary +``` +# Public Test Cases + +## Input 1 + +``` +order_list = [] +order_list = add_order(order_list, 101, 'Apple', 5) +order_list = add_order(order_list, 102, 'Banana', 2) +order_list = update_order(order_list, 101, 10) +order_list = delete_order(order_list, 102) +summary = get_order_summary(order_list) +print(order_list) +print(summary) +``` +## Output 1 + +``` +[{'order_id': 101, 'product': 'Apple', 'quantity': 10}] +{'Apple': 10} +``` + +## Input 2 + +``` +order_list = [] +order_list = add_order(order_list, 201, 'Orange', 6) +order_list = add_order(order_list, 202, 'Apple', 3) +order_list = add_order(order_list, 203, 'Banana', 5) +order_list = update_order(order_list, 202, 8) +order_list = delete_order(order_list, 204) # Invalid ID +summary = get_order_summary(order_list) +print(order_list) +print(summary) +``` +## Output 2 +``` +[{'order_id': 201, 'product': 'Orange', 'quantity': 6}, {'order_id': 202, 'product': 'Apple', 'quantity': 8}, {'order_id': 203, 'product': 'Banana', 'quantity': 5}] +{'Orange': 6, 'Apple': 8, 'Banana': 5} +``` + +# Private Test Cases + +## Input 1 +``` +order_list = [] +order_list = add_order(order_list, 301, 'Milk', 2) +order_list = add_order(order_list, 302, 'Bread', 4) +order_list = add_order(order_list, 303, 'Milk', 3) +order_list = update_order(order_list, 302, 6) +order_list = delete_order(order_list, 304) # Invalid ID +summary = get_order_summary(order_list) +print(order_list) +print(summary) +``` + +## Output 1 +``` +[{'order_id': 301, 'product': 'Milk', 'quantity': 2}, {'order_id': 302, 'product': 'Bread', 'quantity': 6}, {'order_id': 303, 'product': 'Milk', 'quantity': 3}] +{'Milk': 5, 'Bread': 6} +``` + +## Input 2 +``` +order_list = [] +order_list = add_order(order_list, 401, 'Pencil', 10) +order_list = add_order(order_list, 402, 'Notebook', 5) +order_list = add_order(order_list, 403, 'Notebook', 7) +order_list = update_order(order_list, 401, 15) +order_list = delete_order(order_list, 402) +summary = get_order_summary(order_list) +print(order_list) +print(summary) +``` +## Output 2 +``` +[{'order_id': 401, 'product': 'Pencil', 'quantity': 15}, {'order_id': 403, 'product': 'Notebook', 'quantity': 7}] +{'Pencil': 15, 'Notebook': 7} +``` diff --git a/questions_by_Chandan/data_processing_io_question.proq b/questions_by_Chandan/data_processing_io_question.proq deleted file mode 100644 index e69de29..0000000 diff --git a/questions_by_Chandan/data_processing_question.proq b/questions_by_Chandan/data_processing_question.proq deleted file mode 100644 index e69de29..0000000 diff --git a/questions_by_Chandan/data_types_question.proq b/questions_by_Chandan/data_types_question.proq deleted file mode 100644 index e69de29..0000000