Skip to content

Commit 4341d9c

Browse files
committed
Few List-2 Solutions
1 parent 79eeccf commit 4341d9c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

List-2/big_diff.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Given an array length 1 or more of ints, return the difference between the largest and smallest values in the
2+
# array. Note: the built-in min(v1, v2) and max(v1, v2) functions return the smaller or larger of two values.
3+
#
4+
#
5+
# big_diff([10, 3, 5, 6]) → 7
6+
# big_diff([7, 2, 10, 9]) → 8
7+
# big_diff([2, 10, 7, 2]) → 8
8+
9+
def big_diff(nums):
10+
return max(nums) - min(nums)

List-2/counts_ebens.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Return the number of even ints in the given array. Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1.
2+
#
3+
#
4+
# count_evens([2, 1, 2, 3, 4]) → 3
5+
# count_evens([2, 2, 0]) → 3
6+
# count_evens([1, 3, 5]) → 0
7+
8+
def counts_evens(nums):
9+
even = 0
10+
for i in nums:
11+
if i % 2 == 0:
12+
even += 1
13+
return even
14+
15+
16+
def one_liner(nums):
17+
return len(list(filter(lambda x: (x % 2 == 0), nums)))

0 commit comments

Comments
 (0)