-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds count even and odds, functions in list and intro to list solutions
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |