| Method | Description |
|---|---|
| clear() | Removes all items from the dictionary. |
| copy() | Returns a shallow copy of the dictionary. |
| fromkeys(seq[, v]) | Returns a new dictionary with keys from seq and value equal to v (defaults to None). |
| get(key[,d]) | Returns the value of the key. If the key does not exist, returns d (defaults to None). |
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
| post_data = [1, 'Getting started with Rich', 'Ashutosh Krishna'] | |
| post_id = post_data[0] | |
| post_title = post_data[1] | |
| post_author = post_data[2] | |
| print(post_id, post_title, post_author) |
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
| """Sum of Two Numbers | |
| def add(x, y): | |
| return x+y | |
| print(add(2, 3)) | |
| """ | |
| """Sum of Three Numbers | |
| def add(x, y, z): |
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
| from typing import List | |
| from random import shuffle, choice | |
| from rich.console import Console | |
| console = Console() | |
| def get_sentences(filename: str) -> List: | |
| with open(filename) as f: | |
| sentences = list(set(f.read().splitlines())) |
| HTTP METHOD | API ENDPOINT | DESCRIPTION |
|---|---|---|
| GET | /products | Get a list of products. |
| GET | /products?limit=x | Get only x products. |
| GET | /products/<product_id> | Get a single product. |
| POST | /products | Create a new product. |
| PUT | /products/<product_id> | Update a product. |
| PATCH | /products/<product_id> | Partially update a product. |
| DELETE | /products/ | Delete a product. |
| CODE RANGE | CATEGORY |
|---|---|
| 1XX | Informational response |
| 2XX | Successful operation |
| 3XX | Redirection |
| 4XX | Client error |
| 5XX | Server error |
| HTTP METHOD | DESCRIPTION |
|---|---|
| GET | Retrieve existing data |
| POST | Add new data |
| PUT | Update existing data |
| PATCH | Partially update existing data |
| DELETE | Delete data |
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 requests | |
| from bs4 import BeautifulSoup | |
| def get_horoscope(zodiac_sign: int, day: str): | |
| if not "-" in day: | |
| res = requests.get( | |
| f"https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-{day}.aspx?sign={zodiac_sign}") | |
| else: | |
| day = day.replace("-", "") |
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
| @app.route('/<short_id>') | |
| def redirect_url(short_id): | |
| link = ShortUrls.query.filter_by(short_id=short_id).first() | |
| if link: | |
| return redirect(link.original_url) | |
| else: | |
| flash('Invalid URL') | |
| return redirect(url_for('index')) |
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
| from datetime import datetime | |
| from app.models import ShortUrls | |
| from app import app, db | |
| from flask import render_template, request, flash, redirect, url_for | |
| @app.route('/', methods=['GET', 'POST']) | |
| def index(): | |
| if request.method == 'POST': | |
| url = request.form['url'] | |
| short_id = request.form['custom_id'] |