This file contains hidden or 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
def addNumber(x: int, y: int) -> int: | |
return x + y | |
def substractNumber(x: int, y: int) -> int: | |
return x - y | |
def divideNumber(x: int, y: int) -> int: | |
return x / y |
This file contains hidden or 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
package main | |
import "fmt" | |
func addNumber(x, y int) int { | |
return x + y | |
} | |
func subtractNumber(x, y int) int { | |
return x - y |
This file contains hidden or 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
package main | |
import "fmt" | |
func addNumber(x, y int) int { | |
return x + y | |
} | |
func subtractNumber(x, y int) int { | |
return x - y |
This file contains hidden or 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
package main | |
import "fmt" | |
func addNumber(x, y int) int { | |
return x + y | |
} | |
func subtractNumber(x, y int) int { | |
return x - y |
This file contains hidden or 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
"""Slice array""" | |
num = [1, 2, 3, 4, 5, 6, 7] | |
"""Get all array except first value""" | |
val_1 = num[1::] | |
# val 1 is [2, 3, 4, 5, 6, 7] | |
"""Get all array except last value""" | |
val_2 = num[:-1] | |
# val 2 is [1, 2, 3, 4, 5, 6] |
This file contains hidden or 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
from itertools import groupby | |
"""grouping value based on consecutive value""" | |
num = "aaabbccc" | |
group_value = list(list(val) for _, val in groupby(num)) | |
# group value is [['a', 'a', 'a'], ['b', 'b'], ['c', 'c', 'c']] |
This file contains hidden or 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
from itertools import chain | |
"""Flatten nested list""" | |
num = [[1, 2, 3], [4, 5, 6]] | |
flat_list = list(chain(*num)) | |
# flat list is [1, 2, 3, 4, 5, 6] |
This file contains hidden or 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
from collections import OrderedDict | |
"""remove duplicate""" | |
num = [9, 9, 8, 7, 1, 3, 5, 3, 4, 7, 8, 2] | |
"""if order is not important""" | |
unique_sort_num = list(set(num)) | |
# [1, 2, 3, 4, 5, 7, 8, 9] | |
"""if order is important""" |
This file contains hidden or 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
"""Find index min and max""" | |
num = [5, 8, 3, 4, 9, 2, 5, 10] | |
def get_min(arr: list) -> int: | |
return min(range(len(arr)), key=arr.__getitem__) | |
def get_max(arr: list) -> int: | |
return max(range(len(arr)), key=arr.__getitem__) |
This file contains hidden or 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
"""Merge dictionary""" | |
words = {"a": 1, "b": 2, "c": 3} | |
number = {"1": 1, "2": 2, "3": 3} | |
"""example 1""" | |
ex_1 = {**words, **number} | |
# merge dictionary a, b = {'a': 1, 'b': 2, 'c': 3, '1': 1, '2': 2, '3': 3} | |
"""example 2""" | |
ex_2 = dict(words.items() | number.items()) |