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 calc(a, b): | |
| add = a+b | |
| sub = a-b | |
| mul = a*b | |
| return add, sub, mul | |
| add, sub, mul = calc(20, 10) | |
| print(add) | |
| print(sub) |
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
| #Lambda function | |
| ages = [33, 90, 17, 15, 21, 60, 5] | |
| adults = list(filter(lambda age: age>=18, ages)) | |
| print(adults) |
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 list_to_dictionary(keys, values): | |
| return dict(zip(keys, values)) | |
| list1 = ["Name", "Age", "City"] | |
| list2 = ['Roy', 26, "New York"] | |
| print(list_to_dictionary(list1, list2)) |
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
| import itertools | |
| mylist = [[-2, -3], [10, 30], ['apple', 'orange']] | |
| print(list(itertools.chain.from_iterable(mylist))) |
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
| import os | |
| import pandas | |
| print(os) | |
| print(pandas) |
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
| matrix = [[1, 2, 3], [4, 5, 6]] | |
| print("Before transpose:") | |
| for row in matrix: | |
| print(row) | |
| #transpose in a single line | |
| transposed_matrix = zip(*matrix) | |
| print("After transpose:") | |
| for row in transposed_matrix: |
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
| import sys | |
| myvar = 15 | |
| mylist = [1,2,3,4,5] | |
| mystr = "Hello world!" | |
| print(sys.getsizeof(myvar)) | |
| print(sys.getsizeof(mylist)) | |
| print(sys.getsizeof(mystr)) |
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
| mylist = [1,2,3,3,4,'John', 'Ana', 'Mark', 'John'] | |
| #Method 1 | |
| def remove_duplicate(list_value): | |
| return list(set(list_value)) | |
| print(remove_duplicate(mylist)) | |
| #Method 2 | |
| result = [] |
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
| numbers = [1, 2, 3, 4] | |
| words = ['One', 'Two', 'Three', 'Four'] | |
| result = zip(numbers, words) | |
| # converting values to print as set | |
| result = set(result) | |
| print('The zipped result is: ', result) |
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
| #List containing even numbers | |
| even_List = [number for number in range(10) if number%2 == 0] | |
| #Square of given numbers | |
| square_List = [number * number for number in range(10)] | |
| print("Even numbers are: ", even_List) | |
| print("Squared numbers are: ", square_List) |
NewerOlder