Python – Swap Values

February 22nd, 2012 No comments

In other languages:

temp = a
a = b
b = temp
 

In Python:

b, a = a, b
 

The comma is the tuple constructor syntax. A tuple is created on the right (tuple packing). A tuple is the target on the left (tuple unpacking). The right-hand side is unpacked into the names in the tuple on the left-hand side.

Further examples of unpacking:

>>> l =['David', 'Pythonista', '+1-514-555-1234']
>>> name, title, phone = l
>>> name
‘David’
>>> title
‘Pythonista’
>>> phone
‘+1-514-555-1234′
 

Useful in loops over structured data:

l (L) above is the list we just made (David’s info). So people is a list containing two items, each a 3-item list.

 

>>> people = [l, ['Guido', 'BDFL', 'unlisted']]
>>> for (name, title, phone) in people:
… print name, phone

David +1-514-555-1234
Guido unlisted
 

Each item in people is being unpacked into the (name, title, phone) tuple.

Arbitrarily nestable (just be sure to match the structure on the left & right!):

 

>>> david, (gname, gtitle, gphone) = people
>>> gname
‘Guido’
>>> gtitle
‘BDFL’
>>> gphone
‘unlisted’
>>> david
['David', 'Pythonista', '+1-514-555-1234']
 

[from: Code like a pythonista]

Share
Categories: Python Tags: ,

Quotes from The Start-up of YOU

February 16th, 2012 No comments

Excerpts from atticle @ Forbes.

1. “All humans are entrepreneurs not because they should start companies but because the will to create is encoded in human DNA.”

2. “Entrepreneurship is a life idea, not a stricly business one; a global idea, not a strictly American one.”

3. “Before dreaming about the future or marking plans, you need to articulate what you already have going for you – as entrepreneurs do.”

4. “When you’re doing work you care about, you are able to work harder and better.”

5. “You remake yourself as you grow and as the world changes. Your identity doesn’t get found. It emerges.”

6. “Whatever the situation, actions, not plans, generate lessons that help you test your hypotheses against reality.”

7. “No matter how brilliant your mind or strategy, if you’re playing a solo game, you’ll always lose out to a team.”

8. “The fastest way to change yourself is to hang out with people who are already the way you want to be.”

9. “If you want to build  a strong network that will help you move ahead in your career, it’s vital to first take stock of the connections you already have.”

10. “What will get you somewhere is being able to access the information you need, when you need it.”

[Amazon Link: the Start-up of YOU]

[Original article @ Forbes ]

Share
Categories: Personal Tags: , ,

US Congress Passes $11 Bill for FAA to update from RADAR to GPS

February 8th, 2012 No comments

At last congress is approving update of traditional RADAR based air traffic control of planes to GPS. The deadline for upgrade is june 2015. What it brings to the table for FAA? I guess better update rates of positions than what they had from RADAR, 6 to 12 seconds.
I always though that at least in US, they use latest technologies when multiple lives are involved. But seems like it took them 20 years as GPS was introduced for civilian use in 1992/93.
[Original Story at : Mobile Tech USA]

Share
Categories: Location Based Services Tags: , ,