You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Roger Chen edited this page Jan 14, 2016
·
10 revisions
Useful Python functions
Generate a list of class logins
importstringimportitertoolsdefgenerate_login_list(num, minimum_length=2):
""" Generates a list of class logins, starting with 2-letter logins. Does not include logins that start with 't' or 'r'. >>> generate_login_list(3) ['aa', 'ab', 'ac'] """accounts= []
alph=string.lowercasenon_reserved=lambdaaccount: account[0] notin ('t', 'r')
forlengthinitertools.count(minimum_length):
accounts.extend(map(''.join, filter(non_reserved, itertools.product(alph, repeat=length))))
iflen(accounts) >=num:
returnaccounts[:num]