Fix Python – Find intersection of two nested lists?

I know how to get an intersection of two flat lists:
b1 = [1,2,3,4,5,9,11,15]
b2 = [4,5,6,7,8]
b3 = [val for val in b1 if val in b2]

or
def intersect(a, b):
return list(set(a) & set(b))

print intersect(b1, b2)

But when I have to find intersection for nested lists then my problems starts:
c1 = [1, 6, 7, 10, 13, 28, 32, 41, 58, 63]
c2 = [[13….

Fix Python – How to download image using requests

I’m trying to download and save an image from the web using python’s requests module.
Here is the (working) code I used:
img = urllib2.urlopen(settings.STATICMAP_URL.format(**data))
with open(path, ‘w’) as f:
f.write(img.read())

Here is the new (non-working) code using requests:
r = requests.get(settings.STATICMAP_URL.format(**data))
if r.sta….

Fix Python – What is the standard way to add N seconds to datetime.time in Python?

Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so that 11:34:59 + 3 = 11:35:02, for example?
These obvious ideas don’t work:
>>> datetime.time(11, 34, 59) + 3
TypeError: unsupported operand type(s) for +: ‘datetime.time’ and ‘int’
>>> datetime.time(11, 34, 59) + datetime.timedelta(0, 3)
Ty….

Fix Python – How to update/upgrade a package using pip?

What is the way to update a package using pip?
those do not work:
pip update
pip upgrade

I know this is a simple question but it is needed as it is not so easy to find (pip documentation doesn’t pop up and other questions from stack overflow are relevant but are not exactly about that)
….

Fix Python – How to extract the substring between two markers?

Let’s say I have a string ‘gfgfdAAA1234ZZZuijjk’ and I want to extract just the ‘1234’ part.
I only know what will be the few characters directly before AAA, and after ZZZ the part I am interested in 1234.
With sed it is possible to do something like this with a string:
echo “$STRING” | sed -e “s|.*AAA\(.*\)ZZZ.*|\1|”

And this will give me 1234 a….

Fix Python – Case insensitive regular expression without re.compile?

In Python, I can compile a regular expression to be case-insensitive using re.compile:
>>> s = ‘TeSt’
>>> casesensitive = re.compile(‘test’)
>>> ignorecase = re.compile(‘test’, re.IGNORECASE)
>>>
>>> print casesensitive.match(s)
None
>>> print ignorecase.match(s)
<_sre.SRE_Match object at 0x02F0B608>

Is there a way to do the same, but without us….