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
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. |
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
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 |
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
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)) |
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
# 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): |
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
# 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): |
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 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. |
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 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') |
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 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+)') |
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
#! 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 |
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 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') |