This file contains 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 numpy as np | |
import random | |
def one_to_five(): | |
two_D_array = np.array([[1, 2, 3, 4, 5], [6, 7, 1, 2, 3], [4, 5, 6, 7, 1], [2, 3, 4, 5, 6], [7, 0, 0, 0, 0]], int) | |
x = random.randrange(1, 6, 1) | |
y = random.randrange(1, 6, 1) |
This file contains 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
__author__ = 'rakesh' | |
# print out the highest palindrome and length of each palindrome exist in the string | |
def Palindrome(text): | |
list = [] | |
palindrome = [] | |
new_list = [] | |
f = [] |
This file contains 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 tweepy import Stream | |
from tweepy import OAuthHandler | |
from tweepy.streaming import StreamListener | |
import urllib, json | |
import urllib2 | |
ckey = '' | |
csecret = '' | |
atoken = '' | |
asecret = '' |
This file contains 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
1- curl www.website.com/ | grep '^<a href=.*title=$' > new1.txt | |
this will fetch all the links stored in a given website and display it into the file new1.txt | |
2- |
This file contains 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
Regular Expression #use this link http://regexone.com/lesson/3 | |
1- | |
match text abc123xyz ? | |
match text define “123” ? | |
match text var g = 123; | |
.* -> . means select any character, *one or more character | |
[a-z0-9]+ -> it will only cover abc123xyz because it will take any character between a-z and 0-9 |
This file contains 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
a = [7, 2, 2, 3, 3, 4, 4, 55, 55, 100, 100] | |
b = 0 | |
#for i in range(len(a)): | |
#you will find the forever alone element in the array | |
def XOR(): |
This file contains 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
__author__ = 'rakesh' | |
import math | |
''' | |
Q3. Write a code to find all subsets of a given set:- | |
Exp: {1,2,3} will give {1},{2},{3},{1,2},{1,3},{2,3},{1,2,3} | |
''' | |
''' |
This file contains 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
__author__ = 'rakesh' | |
class BinarySearchTree: #now you can perform any type of opertion on this tree | |
def __init__(self, value): | |
self.value = value | |
self.right = None | |
self.left = None |
This file contains 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
Red Black Tree is a Binary Search Tree which the following red-black properties | |
1- Every node is either black or red | |
2- Every leaf(NULL) is black | |
3- if a node is red then both its children will be black | |
4- Every simple path from a node to a descendent leaf contains the same number of black nodes. | |
<implies that on any path from the root to a leaf, red nodes must not be adjacent. However, any number of black nodes may appear in a sequence > | |
Image - <https://www.cs.auckland.ac.nz/software/AlgAnim/fig/rb_tree1.gif> this is a basic red black tree |
This file contains 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
Video referred for merge sort <https://www.youtube.com/watch?v=jeaxzxErLKk> | |
def mergeSort(alist): | |
2 print("Splitting ",alist) | |
3 if len(alist)>1: | |
4 mid = len(alist)//2 | |
5 lefthalf = alist[:mid] | |
6 righthalf = alist[mid:] | |
7 | |
8 mergeSort(lefthalf) |
OlderNewer