[ create a new paste ] login | about

Link: http://codepad.org/0EAY6tJ7    [ raw code | output | fork ]

Python, pasted on May 31:
def r(target):
  if target == 'a..z':
    return list('bcdefghijklnmopqrstuvwxy'.join(target.split('..')))
  elif target == 'A..Z':
    return list('BCDEFGHIJKLMNOPQRSTUVWXY'.join(target.split('..')))
  else:
    return ""

def flatten(lst):
  for elm in lst:
    if type(elm) in (tuple, list):
      for i in flatten(elm):
        yield i
    else:
      yield elm

seed_list = [r('a..z'), r('A..Z'), '.', '/']

print seed_list

salt = list( flatten(seed_list) ) # using list
print salt

for e in flatten(seed_list): # uging generator
  print e,

nested = [(' ', ' ', [('a', 'Scott'), ('9', 'vth')]), (' ', ' ', [('a', 'Jenny'), ('9', 'vth')])]
flattened = list( flatten(nested) )
print flattened.count("a")


Output:
1
2
3
[['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'n', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'], '.', '/']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'n', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '.', '/']
a b c d e f g h i j k l n m o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z . / 2


Create a new paste based on this one


Comments: