diff --git a/README.md b/README.md index 5d400cf..218038b 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,9 @@ My solutions to competitive programming problems in [Geeks for Geeks](https://au |Find immediate smaller than X|[C++](c++/find_immediate_smaller_than_x.cpp)| |Kth Smallest Element|[C++](c++/kth-smallest-number.cpp)| |Alone in Couple|[C++](c++/alone-in-couple.cpp)| +|Intro to list|[Python](python/intro-to-list.py)| +|Count even odd python|[Python](python/count-even-odd-python.py)| +|Functions in list|[Python](python/functions-in-list.py)| |Pair sum in vector(sum second element of the second element)|[C++](c++/pair-sum-in-vector.cpp)| |Index of the first repeating element |[C++](c++/first-repeating-element.cpp)| |K-th element of two sorted Arrays(merge of two arrays)|[C++](c++/k-th-element-of-two-sorted-arrays.cpp)| diff --git a/python/count-even-odd-python.py b/python/count-even-odd-python.py new file mode 100644 index 0000000..63a5867 --- /dev/null +++ b/python/count-even-odd-python.py @@ -0,0 +1,19 @@ +# https://practice.geeksforgeeks.org/problems/count-even-odd-python/1/?track=python-module-5&batchId=119 +def count_even_odd(n, arr): + c_e = 0 + c_o = 0 + + pair = list() + + # your code here + for x in arr: + if x%2 == 0: + c_e += 1 + else: + c_o += 1 + + pair.append(c_e) + pair.append(c_o) + + return pair + diff --git a/python/functions-in-list.py b/python/functions-in-list.py new file mode 100644 index 0000000..0576f69 --- /dev/null +++ b/python/functions-in-list.py @@ -0,0 +1,24 @@ +# https://practice.geeksforgeeks.org/problems/functions-in-lists-python/1/?track=python-module-5&batchId=11 + +# Function to sort the list +def sort_arr(arr): + arr.sort() + +# Function to join list elements +# with string as delimiter +def join_list(arr, string): + return string.join(arr) + + +# Function to reverse array elements +def rev_arr(arr): + arr.reverse() + +# Function to insert element at index +def insert_arr(arr, index, element): + arr.insert(index, element) + +# Function to pop element from array at index +def pop_arr(arr, index): + arr.pop(index) + diff --git a/python/intro-to-list.py b/python/intro-to-list.py new file mode 100644 index 0000000..7ba54b5 --- /dev/null +++ b/python/intro-to-list.py @@ -0,0 +1,9 @@ +# https://practice.geeksforgeeks.org/problems/intro-to-lists-python/1/?track=python-module-5&batchId=119 +def check_zero(size_array, arr): + + # complete the if statement to check + # if first or last element in list is 0 + if arr[0] == 0 or arr[size_array-1] == 0 : + return True + + return False