Skip to content

Instantly share code, notes, and snippets.

View anilpai's full-sized avatar
:octocat:
Coding

Anil Pai anilpai

:octocat:
Coding
View GitHub Profile
class Student:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
@classmethod
def from_string(cls, name_str):
first_name, last_name = map(str, name_str.split(' '))
student = cls(first_name, last_name)
@anilpai
anilpai / flatten.py
Created February 2, 2017 01:29
Flatten a list
def flatten(lst):
'''
Flattens a list of lists.
'''
r = []
for x in lst:
if type(x) is list:
r.extend(x)
else:
r.append(x)