Python @ Codecademy

badge_Python_statisticsInternet Protocols and Support
https://docs.python.org/3.4/library/internet.html

https://docs.python.org/3.4/library/urllib.request.html

====================================

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):
print(i)
Python
>>> languages[2]
‘Python’

badge_Python_advanced_topics
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):
self.name = 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.name, self.flavor)

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

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

lemon.description()
lemon.is_edible()

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)

codecademy_classes

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)

print(my_car.condition)

my_car.drive_car()

print(my_car.condition)

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”)

f.close()

=============

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

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

Codecademy_FileIO

Advertisements

Python The Hard Way (3rd ed.)

Learn Python
The Hard Way. 3rd Edition.
http://learnpythonthehardway.org/book

Exercise 32: Loops and Lists
Exercise 33: While Loops

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

break statements on loops
https://docs.python.org/3.6/tutorial/controlflow.html

==========================

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:
            new_list.append(elemento)
    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):
            new_list.append(i)
    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
else:
return sequence[(len(sequence) // 2)]

badge_practice_makes

==========================

>>> listaA = [[]] * 3
>>> listaA
[[], [], []]
>>> listaB = [[] for i in range(3)]
>>> listaB
[[], [], []]
>>> listaA == listaB
True
>>> 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
http://www.npr.org/blogs/thesalt/2013/08/21/214202886/inside-the-beef-industrys-battle-over-growth-promotion-drugs

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.

related:
July 8, 2013
http://www.npr.org/blogs/parallels/2013/07/08/199168194/EU-U-S-Trade-A-Tale-Of-Two-Farms
He says there are philosophical differences when it comes to genetically modified crops

September 29, 2009
http://www.npr.org/templates/story/story.php?storyId=113314725
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
http://www.npr.org/blogs/thesalt/2014/10/13/355115593/friction-can-save-your-sandwich-and-other-tips-for-better-bites

“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.

http://www.sporkful.com

Joan Borysenko: Resilience

Surviving And Thriving When Times Are Tough with Joan Borysenko, Ph.D.
October 22, 2014
by New Dimensions
http://www.newdimensions.org/surviving-and-thriving-when-times-are-tough-with-joan-borysenko

“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)

http://www.joanborysenko.com

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.
http://jama.jamanetwork.com/article.aspx?articleid=1917421

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:
http://www.npr.org/blogs/health/2014/10/22/357831203/banned-drugs-still-turning-up-in-weight-loss-supplements