Skip to content

Instantly share code, notes, and snippets.

View richardpascual's full-sized avatar

Rich Pascual richardpascual

View GitHub Profile
# Example 1
drinks = ["espresso", "chai", "decaf", "drip"]
caffeine = [64, 40, 0, 120]
zipped_drinks = zip(drinks, caffeine)
drinks_to_caffeine = {key:value for key, value in zipped_drinks}
print(drinks_to_caffeine)
@richardpascual
richardpascual / reversed_list.py
Last active June 23, 2021 23:24
Compare two lists, identify if one is the reverse of the other.
#Write your function here
def reversed_list(lst1, lst2):
for index in range(len(lst1)):
if lst1[index] != lst2[len(lst2) - 1 - index]:
return False
return True
#Uncomment the lines below when your function is done
@richardpascual
richardpascual / odd_indices.py
Last active June 23, 2021 17:52
Looping: Print the value for every position with an odd index
# print the value for every position with an odd index.
#Write your function here
def odd_indices(lst):
new_list = []
for idx in lst:
if lst.index(idx) % 2 != 0:
new_list.append(idx)
return(new_list)
@richardpascual
richardpascual / middle_element.py
Last active June 18, 2021 23:09
Get the middle element. If it's an even number of elements, average the middle two values.
#Write your function here
def middle_element(lst):
if len(lst) % 2 == 0:
sum = lst[int(len(lst)/2)] + lst[int(len(lst) / 2) - 1]
return sum / 2
else:
return lst[int(len(lst)/2)]
#Uncomment the line below when your function is done
#Write your function here
def more_frequent_item(lst, item1, item2):
if lst.count(item1) >= lst.count(item2):
return item1
else:
return item2
#Uncomment the line below when your function is done
print(more_frequent_item([2, 3, 3, 2, 3, 2, 3, 2, 3], 2, 3))
@richardpascual
richardpascual / double_index.py
Last active June 18, 2021 22:22
Double the list value for the referenced index position.
#Write your function here
def double_index(lst, index):
if index >= len(lst):
return lst
newlst = lst[0:index]
newlst.append(lst[index]*2)
return newlst + lst[index+1:]
#Uncomment the line below when your function is done
@richardpascual
richardpascual / remove_middle.py
Last active June 17, 2021 18:45
Remove middle of a list based on parameters identifying the index range
#Write your function here
def remove_middle(lst, start, end):
vals = lst
for num in range(start, end):
del vals[num]
return vals
#Uncomment the line below when your function is done
print(remove_middle([4, 8, 15, 16, 23, 42], 1, 3))
#Write your function here
def every_three_nums(start):
cnt = start
nums = [start]
while cnt < 100:
cnt += 3
nums.append(cnt)
return nums
@richardpascual
richardpascual / pincessa
Last active April 3, 2017 16:11
A story in pi language
kumusta sa visita hapon ikaw, maganda?
ay meron, ganda [sila] pero pobre sa ako. pobre sa ako.
ma saktan sa puso?
ay sakit.
sa princess ma'aas ako.
bitaw, ikaw mas matanda y ma baho ko.
seguro, y sobre sa pangit mo.
sabe sa hapon y studia?
hindi naman. wala sa ko.
@richardpascual
richardpascual / pi
Last active April 3, 2017 16:17
Pilipino Lexicon
ito lenguas sa pilipinas. meronong ito?
tagalog: national dialect [1]
hindi: no
sabe: know
kumusta, magandang umaga: greeting (ex. someone from Japan/ha'pon: ohayoo gozaimasu)
hapon: evening (end of day)
pangit <> ganda
wa: slang wala [3]