Skip to content

Instantly share code, notes, and snippets.

import collections
import pprint
facilities:list = list()
medicare_facility:collections.namedtuple = collections.namedtuple("facility",
["id", "facility_name", "address", "city", "state", "zip"])
facilities.append(
medicare_facility(
id="30084",
@raeq
raeq / list_comprehension_01.py
Created May 5, 2020 20:35
List Comprehension
mytext:str = "Hello, World!"
characters:list = [current_letter.title() for current_letter in mytext if current_letter.isalpha()]
my_new_text:str = "".join(characters)
print(my_new_text)
mytext:str = "Hello, World!"
characters:list = list(mytext)
print(len(characters))
print(characters[7])
characters.insert(6, "-")
characters.append("!!")
print(characters)
mytext = "".join(characters)
print(mytext)
recorded_birds = ["crow", "sparrow", "sparrow", "sparrow", "crow", "robin"]
recorded_species:set = set(recorded_birds)
print(recorded_birds)
print(recorded_species)
@raeq
raeq / colours01.py
Last active May 5, 2020 07:57
Compound Tuples
import collections
rgbvalue = collections.namedtuple("rgb", ["red", "green", "blue"])
htmlcolour = collections.namedtuple("htmlcolour", ["name", "rgbvalue"])
colours:set = set()
htmltuple = htmlcolour("Red", rgbvalue(red=0xff, green=0x00, blue=0x00))
colours.add(htmltuple)
@raeq
raeq / tuples02.py
Last active May 5, 2020 07:55
Named tuples
import collections
geolocation = collections.namedtuple("geolocation", ["latitude", "longitude"])
eiffel = geolocation(48.858093, 2.294694)
print(eiffel.latitude)
print(eiffel.longitude)
@raeq
raeq / tuples01.py
Created May 3, 2020 19:16
Casting sets and tuples
geolocation:tuple = (25.001, 25.001)
students:set = {"Harry", "Tom", "Jane", "Sally"}
print(set(geolocation))
print(tuple(students))
@raeq
raeq / sets01.py
Created May 3, 2020 12:43
Working with Sets
citrusfruit:set = {"oranges", "lemons", "limes", "satsumas", "nectarines"}
treefruit:set = {"apples", "pears", "cherries", "plums", "peaches", "plums", "cherries", "oranges", "lemons", "limes"}
stonefruit:set = {"cherries", "plums", "peaches", "nectarines"}
#tree fruit with stones
print(treefruit.intersection(stonefruit))
#tree fruit which are citrus
print(treefruit.intersection(citrusfruit))
i:float = float(99.895321721389127643)
print(i)
print(round(i,2))
print(f"{i:.2f}")
from decimal import *
setcontext(BasicContext)
i:Decimal = Decimal(0.0)
for value in range(10):
i += Decimal(0.1)
print(i)