Python Suggestions
Numpy- How to find eigen value and eigen vectors
[Link]
How to find N dimensional array using numpy
[Link]
What is data frame how to read files using data frame
[Link]
Lamda function
Map , reduce , filter
[Link]
How to read a file ( read and readline )
[Link]
How to find and replace within a file
[Link]
Binary search using recursion
[Link]
Sort- selection, bubble
[Link]
Defination of list tuple set dictionary
[Link]
What is get method in dictionary
Definition and Usage
The get() method returns the value of the item with the specified key.
Syntax
[Link](keyname, value)
Parameter Values
Parameter Description
keyname Required. The keyname of the item you want to return the value from
value Optional. A value to return if the specified key does not exist.
Default value None
More Examples
Example
Try to return the value of an item that do not exist:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = [Link]("price", 15000)
print(x)
What is item
Definition and Usage
The items() method returns a view object. The view object contains the key-value pairs of the dictionary,
as tuples in a list.
The view object will reflect any changes done to the dictionary, see example below.
Syntax
[Link]()
Parameter Values
No parameters
More Examples
Example
When an item in the dictionary changes value, the view object also gets updated:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = [Link]()
car["year"] = 2018
print(x)
What is zip method
Definition and Usage
The zip() function returns a zip object, which is an iterator of tuples where the first item in each passed
iterator is paired together, and then the second item in each passed iterator are paired together etc.
If the passed iterables have different lengths, the iterable with the least items decides the length of the
new iterator.
Syntax
zip(iterator1, iterator2, iterator3 ...)
Parameter Values
Parameter Description
iterable1, iterable2, Iterable objects that will be joined together
iterable3 ...
More Examples
Example
If one tuple contains more items, these items are ignored:
a = ("John", "Charles", "Mike")
b = ("Jenny", "Christy", "Monica", "Vicky")
x = zip(a, b)
How to find gcd of two numbers using recursion
Note: The GCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers is the
largest number that divides both of them.
Examples:
Input: a = 20, b = 28
Output: 4
Explanation: The factors of 20 are 1, 2, 4, 5, 10 and 20. The factors of 28 are 1, 2, 4, 7, 14 and 28. Among
these factors, 1, 2 and 4 are the common factors of both 20 and 28. The greatest among the common
factors is 4.
Input: a = 60, b = 36
Output: 12
Naive Approach for GCD of two numbers:
The basic idea is to find the minimum of the two numbers and find its highest factor which is also a
factor of the other number.
Below is the code implementation of the above idea:
Output
GCD of 98 and 56 is 14
Time Complexity: O(min(a,b))
Auxiliary Space: O(1)