Skip to content

Instantly share code, notes, and snippets.

View Ovicron's full-sized avatar
🐜

Ovicron

🐜
View GitHub Profile
@Ovicron
Ovicron / list_and_ranges_lesson.py
Created April 25, 2020 00:49
list/ranges/zip/append
first_names = ["Ainsley", "Ben", "Chani", "Depak"] # Used with ZIP
age = [] # Empty List
age.append(42) # Appending/Adding to empty list
all_ages = [32, 41, 29, 42] # Used with ZIP
name_and_age = zip(first_names, all_ages) # Using "ZIP" to pair/combine other lists.
@Ovicron
Ovicron / working_with_lists.py
Created April 25, 2020 17:06
len/count/sort/indexing
inventory = ['twin bed', 'twin bed', 'headboard', 'queen bed', 'king bed', 'dresser', 'dresser', 'table', 'table', 'nightstand', 'nightstand', 'king bed', 'king bed', 'twin bed', 'twin bed', 'sheets', 'sheets', 'pillow', 'pillow']
inventory_len = len(inventory) # Number of elements inside a list (number or strings)
first = inventory[0] # Index 0 means the first item in list
last = inventory[-1] # Negative means counts from last item in list
inventory_2_6 = inventory[2:6] # Index of 2 UP-TO 6 but doesn't include 6
toppings = ["pepperoni", "pineapple", "cheese", "sausage", "olives", "anchovies", "mushrooms"]
prices = [2, 6, 1, 3, 2, 7, 2]
num_pizzas = len(toppings)
print("We sell " + str(num_pizzas) + " different kind of pizzas!")
pizzas = list(zip(prices, toppings))
# Using length function to find last element on a list along with IF/ELIF statements.
def larger_list(lst1, lst2):
if len(lst1) > len(lst2):
return lst1[-1:]
elif len(lst2) > len(lst1):
return lst2[-1:]
elif len(lst1) == len(lst2) and len(lst2) == len(lst1):
# Guess the number game
import random
name = input("Hello, what is your name? ")
print(f"Hello {name}, I am thinking of a number between 1 - 10. Can you get it?")
secret_Num = random.randint(1, 10)
for guess_Count in range(1, 6):
import pprint # Imports pretty print
letter_counter = input("Enter text that you want to count: ") # Letters inside here are counted (user input)
count = {} # Empty dictionary that contains the counted letters
for i in letter_counter.upper(): # for item in letter_counter input and upper method makes sure so its all upper case.
count.setdefault(i, 0) # we use "setdefault" which is a dictionary method on "count" to add non-existing key.
import re
# Using Regex re.compile to define what to search for ( use parenthesis to group stuff )
search_phone_num = re.compile(r'(\d\d\d)-(\d\d\d-\d\d\d\d)')
# Can use findall method or search method
mo = search_phone_num.search(r' My phone number is 343-943-4582 please call me! 394-393-2222 TEL')
import re
lyrics = '''7 Swans a Swimming
6 Geese a Laying
5 Golden Rings
4 Calling Birds
3 French Hens
2 Turtle Doves'''
xmas_regex = re.compile(r'(\d+\s\w+)')
@Ovicron
Ovicron / email_and_number_scraper.py
Last active May 3, 2020 21:18
this will scrape email and phone numbers from your clipboard if you have a full page copied and organizes the numbers/emails together.
#! python3
import re
import pyperclip
import pprint
# Create a regex for phone numbers
phone_regex = re.compile(r'''
# 415-555-0000, 555-0000, (415) 555-0000, 555-0000 ext 12345, ext. 12345, x12345
@Ovicron
Ovicron / ebay_price_scraper.py
Last active May 6, 2020 16:20
scrapes ebay product and returns price of item
import bs4
import requests
def get_ebay_price(product_url):
res = requests.get(product_url)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
page_elem = soup.select('#prcIsum')