Skip to content

Instantly share code, notes, and snippets.

@Nurdok
Nurdok / doubleiter3.py
Created July 13, 2012 23:20
Double Iteration in List Comprehension
>>> seq = ['abc', 'def', 'g', 'hi']
... [y for x in seq if len(seq) > 1 for y in x if y != 'e']
['a', 'b', 'c', 'd', 'f', 'g', 'h', 'i']
@Nurdok
Nurdok / singleton_type.py
Created April 26, 2012 15:08
Singleton Implementation in Python Using Metaclasses
class SingletonType(type):
def __call__(cls, *args, **kwargs):
try:
return cls.__instance
except AttributeError:
cls.__instance = super(SingletonType, cls).__call__(*args, **kwargs)
return cls.__instance