Skip to content

Instantly share code, notes, and snippets.

View arjun921's full-sized avatar
🧠
Perpetual Learner

Arjun Sunil arjun921

🧠
Perpetual Learner
View GitHub Profile
@arjun921
arjun921 / 27_December_2016_Decode_A_Web_Page_Two.py
Created December 27, 2016 10:37
Using the requests and BeautifulSoup Python libraries, print to the screen the full text of the article on this website: http://www.vanityfair.com/society/2014/06/monica-lewinsky-humiliation-culture. The article is long, so it is split up between 4 pages. Your task is to print out the text to the screen so that you can read the full article with…
import requests
from bs4 import BeautifulSoup
url = "http://www.vanityfair.com/style/society/2014/06/monica-lewinsky-humiliation-culture"
r = requests.get(url)
soup = BeautifulSoup(r.text,"html5lib")
for content in soup.find_all(class_="content-section"):
for para in content.find_all('p'):
for child in para.descendants:
@arjun921
arjun921 / 29_December_2016_Write_To_A_File.py
Created December 29, 2016 01:18
Writes paragraph output from website to a file.
import requests
from bs4 import BeautifulSoup
url = "http://www.vanityfair.com/style/society/2014/06/monica-lewinsky-humiliation-culture"
r = requests.get(url)
open_file = open('file.txt','w')
soup = BeautifulSoup(r.text,"html5lib")
for content in soup.find_all(class_="content-section"):
for para in content.find_all('p'):
for child in para.descendants:
s = input()
s = s.upper()
lens = len(s)
consonants = set()
vowels = set()
unique = []
substrings = []
stuart = []
kevin = []
kevintot,stuarttot = 0,0
"""Final 4"""
pbook = {}
search=[]
for x in range(int(input())):
a = input().strip().split(' ')
pbook[str(a[0])]=int(a[1])
s=True
while s:
s=input()
search.append(str(s))
@arjun921
arjun921 / PalindromeFunc.py
Created January 16, 2017 15:19
[HOMEWORK]Define function ispallindrome that recognizes palindromes
"""Solved"""
def ispallindrome(arr,s,temp):
for i in arr:
temp -= 1
s.append((arr[temp]))
s = "".join(s)
arr = "".join(arr)
if s==arr:
return True
else:
@arjun921
arjun921 / PresentParticiple.py
Last active January 16, 2017 15:53
[HOMEWORK]In English, the present participle is formed by adding the suffix "ing" to the infinite form EG - going. A simple set of heuristic rules can be given as follows. Rule 1: if the verb ends in 'e', drop 'e' and add 'ing'. Rule 2: if the verb ends in 'IE', change it to 'y' and add 'ing' Rule 3. For words consisting of consonant, vowel cons…
"""Final Parital"""
"""Requires Python 3"""
def ingFrom(s):
for x in s:
li.append(x)
if li[len(li)-1]=='e' and li[len(li)-2]!='i':
del li[len(li)-1]
li.append("ing")
elif li[len(li)-1]=='e' and li[len(li)-2]=='i':
del li[len(li)-1]
@arjun921
arjun921 / vowFunc.py
Created January 16, 2017 15:55
[HOMEWORK]Function that takes a character, and returns True if vowel, False otherwise
"""Solution"""
def vowOrNot(c):
c = c.upper()
if c in 'AEIOU':
return True
else:
return False
print(vowOrNot(input('Enter character to check if Vowel or not')))
"""Solved"""
"""https://www.hackerrank.com/challenges/list-comprehensions"""
x = int(input())
y = int(input())
z = int(input())
n = int(input())
temp = []
lis = []
for i in range(x+1):
for j in range(y+1):
"""Solved"""
ls = []
n = int(input())
for x in range(n):
arr = [arr_temp for arr_temp in input().strip().split(' ')]
ls.append(arr)
s = input()
for i in range(len(ls)):
for j in ls[i]:
if j==s:
temp = [20.0, 20.0, 19.0, 19.0, 21.0]
works = [37.21,37.21,37.2,41,39]
def second_smallest(numbers):
m1, m2 = float('inf'), float('inf')
for x in numbers:
if x <= m1:
m1, m2 = x, m1
elif x < m2:
m2 = x
return m2 sd