Python @ Codecademy

badge_Python_statisticsInternet Protocols and Support


None keyword
example: i = A
i = None

Building lists
evens_to_50 = [i for i in range(51) if i % 2 == 0]

print(filter(lambda x: x % 3 == 0, my_list))

>>>for i in filter(lambda x: x[0] == “P”, languages):
>>> languages[2]

Just a Little BIT

Welcome to an intro level explanation of bitwise operations in Python!

Bitwise operations might seem a little esoteric and tricky at first, but you’ll get the hang of them pretty quickly.

codecademy_bitwiseclass Fruit(object):
“””A class that makes various tasty fruits.”””
def __init__(self, name, color, flavor, poisonous): = name
self.color = color
self.flavor = flavor
self.poisonous = poisonous

def description(self):
print “I’m a %s %s and I taste %s.” % (self.color,, self.flavor)

def is_edible(self):
if not self.poisonous:
print “Yep! I’m edible.”
print “Don’t eat me! I am super poisonous.”

lemon = Fruit(“lemon”, “yellow”, “sour”, False)


class PartTimeEmployee(Employee):
def calculate_wage(self, hours):
self.hours = hours
return hours * 12.00
def full_time_wage(self, hours):
return super(PartTimeEmployee, self).calculate_wage(hours)


class Car(object):
condition = “new”
def __init__(self, model, color, mpg):
self.model = model
self.color = color
self.mpg   = mpg
def display_car(self):
print “This is a %s %s with %s MPG.” % (self.color, self.model, self.mpg)
def drive_car(self):
self.condition = “used”

my_car = Car(“DeLorean”, “silver”, 88)




class ElectricCar(Car):
def __init__(self, model, color, mpg, battery_type):
self.model = model
self.color = color
self.mpg = mpg
self.battery_type = battery_type

my_car = ElectricCar(“Dodge Stratus”, “white”, 18,”molten salt”)
{Is there need to re-define everything??}

Codecademy_Classes2my_list = [i**2 for i in range(1,11)]
# Generates a list of squares of the numbers 1 – 10

f = open(“output.txt”, “w”)

for item in my_list:
f.write(str(item) + “\n”)



with open(“text.txt”, “w”) as textfile:

with open(“text.txt”, “w”) as my_file:
my_file.write(“I am Sam”)



Python The Hard Way (3rd ed.)

Learn Python
The Hard Way. 3rd Edition.

Exercise 32: Loops and Lists
Exercise 33: While Loops

def is_prime(n):
if n < 2:
prime_status = False
prime_status = True
for x in range(2, n):
if n % x == 0:
prime_status = False
return prime_status

break statements on loops


def rev erse(a_string):
    new_list = “”
    for i in range(len(a_string)):
        new_list = new_list + a_string[len(a_string) – i – 1]
    return new_list


def anti_vowel(a_string):
    new_list = “”
    for i in range(len(a_string)):
        if not (a_string[i] in “aeiouAEIOU”):
            new_list = new_list + a_string[i]
    return new_list


def scrabble_score(word):
    puntos = 0
    word = word.lower()
    for i in range(len(word)):
        puntos += score[word[i]]
    return puntos


def censor(text, word):
while (word in text):
lista = text.partition(word)
text = lista[0] + “*” * len(word) + lista[2]
return text

def censor2(text, word):
while (word in text):
lista = text.partition(word)
text = (“*” * len(word)).join([lista[0], lista[2]])
return text


def count(sequence, item):
    contador = 0
    for i in sequence:
        if item == i:
            contador +=1
    return contador


def purify(list_of_numbers):
    new_list = []
    for elemento in list_of_numbers:
        if (elemento % 2) == 0:
    return new_list


def product(list_of_integers):
    temporal = 1
    for i in list_of_integers:
        temporal = temporal * i
    return temporal


def remove_duplicates(lista):
    new_list = []
    for i in lista:
        if not (i in new_list):
    return new_list


def median(sequence):
if len(sequence) == 1:
return sequence[0]
sequence = sorted(sequence)
if (len(sequence) % 2) == 0:
n1 = sequence[(len(sequence) // 2) – 1]
n2 = sequence[len(sequence) // 2]
return (n1 + n2)/2
return sequence[(len(sequence) // 2)]



>>> listaA = [[]] * 3
>>> listaA
[[], [], []]
>>> listaB = [[] for i in range(3)]
>>> listaB
[[], [], []]
>>> listaA == listaB
>>> listaA[0].append(3)
>>> listaA
[[3], [3], [3]]
>>> listaB[0].append(3)
>>> listaB
[[3], [], []]

Beef industry & growth-promotion drugs

Inside The Beef Industry’s Battle Over Growth-Promotion Drugs
August 21, 2013

When the drug company Merck Animal Health announced plans to suspend sales of its Zilmax feed additive last week, many observers were shocked.

Yet concern about Zilmax and the class of growth-promotion drugs called beta agonists has been building for some time. In an interesting twist, the decisive pressure on Zilmax did not come from animal welfare groups or government regulators: It emerged from within the beef industry itself, and from academic exper ts who have long worked as consultants to the industry.

Among them is Temple Grandin, a professor of animal science at Colorado State University. Grandin, whose life is the subject of an HBO biopic, has redesigned slaughterhouses to make them more humane.

Around the summer of 2006, she says, she started seeing a new kind of problem among the cattle, especially when the weather got really hot. “You had animals that were stiff and sore-footed, animals that were reluctant to move,” she recalls. “They act like the floor is red-hot. They don’t want to put their feet down. And I had never seen these kinds of symptoms before, ever!”

The problems, she says, affect as many as 1 out of every 5 animals. She’s become increasingly convinced that the problems result from the drugs called beta agonists.

July 8, 2013
He says there are philosophical differences when it comes to genetically modified crops

September 29, 2009
cows wear a patch behind their ear, which releases a synthetic growth hormone.

Friction Can Save Your Sandwich

Friction Can Save Your Sandwich, And Other Tips For Better Bites  
October 13, 2014

“Give a lot of thought to the interior layering of your components,” he says. In particular, “watch out for slippery components like sliced cucumbers, tomatoes and avocados.”

He calls this “the sliced cucumber conundrum.” But it can be solved with “the silver lining of greens.” Instead of keeping all the slippery ingredients together, Pashman recommends separating them with thin layers of greens in between to create friction.

Joan Borysenko: Resilience

Surviving And Thriving When Times Are Tough with Joan Borysenko, Ph.D.
October 22, 2014
by New Dimensions

“Resilience is that recognition that it’s not the end of the world. Furthermore, resilience is more than just bouncing back from the stress, like losing your house or losing your money. It’s an innate transformation, for example, understanding that happiness is an inside job.” She guides us through the warning signs of pessimism and the pitfalls of optimism, and offers up a wealth of suggestions for how we can develop what she calls “stress-hardiness”—to handle all of life’s challenges with resilience, equanimity, and inner peace. (hosted by Michael Toms)

Joan Borysenko, Ph.D. is a psychologist and cell biologist.  She holds a doctorate in medical sciences from Harvard Medical School, and has completed post-doctoral fellowships in behavioral sciences and psychoneuroimmunology. She is a pioneer in integrative medicine and a world-renowned exper t in the mind-body connection. She is a journalist and host of her own radio show.

She is the bestselling author of fourteen books including:
◦Minding the Body, Mending the Mind (De Capo Press 2007)
It’s Not the End of the World: Developing Resilience in Times of Change (Hay House 2009)
◦The PlantPlus Diet Solution: Personalized Nutrition for Life (Hay House 2014)

Topics explored in this dialogue include:
◦What first step you can take today to change your life for the better
◦When stress is a good thing
◦Why optimism can break your heart
◦How “burning out” can be a good thing
◦How you can find your balance when you feel overwhelmed

Banned Drugs in Dietary Supplements

Presence of Banned Drugs in Dietary Supplements Following FDA Recalls
JAMA. 2014;312(16):1691-1693.
Pieter A. Cohen, MD, et al.

The US Food and Drug Administration (FDA) initiates class I drug recalls when products have the reasonable possibility of causing serious adverse health consequences or death.1 Recently, the FDA has used class I drug recalls in an effort to remove dietary supplements adulterated with pharmaceutical ingredients from US markets. Approximately half of all FDA class I drug recalls since 2004 have involved dietary supplements adulterated with banned pharmaceutical ingredients.

journalistic version:

Vegetable intake & genetic variation in taste

Vegetable Intake in College-Aged Adults Is Explained by Oral Sensory Phenotypes and TAS2R38 Genotype.
Chemosens Percept. 2010 Dec 1;3(3-4):137-148.
Duffy VB, et al.

Taste and oral sensations vary in humans.
Some of this variation has a genetic basis, and two commonly measured phenotypes are the bitterness of propylthiouracil (PROP) and the number of fungiform papillae on the anterior tongue.
While the genetic control of fungiform papilla is unclear, PROP bitterness associates with allelic variation in the taste receptor gene, TAS2R38. The two common alleles are AVI and PAV (proline, alanine, valine, and isoleucine); AVI/AVI homozygotes taste PROP as less bitter than heterozygous or homozygous PAV carriers.

In this laboratory-based study, we determined whether taste of a bitter probe (quinine) and vegetable intake varied by taste phenotypes and TAS2R38 genotype in healthy adults (mean age=26 years).
Vegetable intake was assessed via two validated, complementary methods: food records (Food Pyramid servings standardized to energy intake) and food frequency questionnaire (general intake question and composite vegetable groups). Quinine bitterness varied with phenotypes but not TAS2R38; quinine was more bitter to those who tasted PROP as more bitter or had more papillae.
Nontasters by phenotype or genotype reported greater consumption of vegetables, regardless of type (i.e., the effect generalized to all vegetables and was not restricted to those typically thought of as being bitter).
Furthermore, nontasters with more papillae reported greater vegetable consumption than nontasters with fewer papillae, suggesting that when bitterness does not predominate, more papillae enhance vegetable liking.
These findings suggest that genetic variation in taste, measured by multiple phenotypes or TAS2R38 genotype, can explain differences in overall consumption of vegetables, and this was not restricted to vegetables that are predominantly bitter.

cited by:

Polymorphisms influence alcohol taste

Polymorphisms in TRPV1 and TAS2Rs Associate with Sensations from Sampled Ethanol.
Alcohol Clin Exp Res. 2014 Sep 25.
Allen AL, McGeary JE, Hayes JE.

Genetic variation in chemosensory genes can explain variability in individual’s perception of and preference for many foods and beverages.
To gain insight into variable preference and intake of alcoholic beverages, we explored individual variability in the responses to sampled ethanol (EtOH).
In humans, EtOH elicits sweet, bitter, and burning sensations.
Here, we explore the relationship between variation in EtOH sensations and polymorphisms in genes encoding bitter taste receptors (TAS2Rs) and a polymodal nociceptor (TRPV1).

Caucasian participants (n = 93) were genotyped for 16 single nucleotide polymorphisms (SNPs) in TRPV1, 3 SNPs in TAS2R38, and 1 SNP in TAS2R13. Participants rated sampled EtOH on a generalized Labeled Magnitude Scale. Two stimuli were presented: a 16% EtOH whole-mouth sip-and-spit solution with a single time-point rating of overall intensity and a cotton swab saturated with 50% EtOH on the circumvallate papillae (CV) with ratings of multiple qualities over 3 minutes. Area-under-the-curve (AUC) was calculated for the time-intensity data.

The EtOH whole-mouth solution had overall intensity ratings near “very strong.” Burning/stinging had the highest mean AUC values, followed by bitterness and sweetness. Whole-mouth intensity ratings were significantly associated with burning/stinging and bitterness AUC values on the CV. Three TRPV1 SNPs (rs224547, rs4780521, rs161364) were associated with EtOH sensations on the CV, with 2 (rs224547 and rs4780521) exhibiting strong linkage disequilibrium. Additionally, the TAS2R38 SNPs rs713598, rs1726866, and rs10246939 formed a haplotype, and were associated with bitterness on the CV. Last, overall intensity for whole-mouth EtOH associated with the TAS2R13 SNP rs1015443.

These data suggest genetic variation in TRPV1 and TAS2Rs influence sensations from sampled EtOH and may potentially influence how individuals initially respond to alcoholic beverages.

Bitterness; Burn; Ethanol; TRPV1; Taste Phenotype

journalistic version: