This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 24th, 2012  |  syntax: None  |  size: 0.39 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. a = [1,2]
  2.  
  3. for ctr in range(0,len(a)):
  4.     print ctr
  5.     if len(a) < 10:
  6.         a.append(2)
  7.        
  8. while len(a) < 10:
  9.     a.append(2)
  10.        
  11. a.extend([2] * (10 - len(a)))
  12.        
  13. a += [2] * (10 - len(a))
  14.        
  15. a += [2] * (10 - len(a))
  16.        
  17. a = [1,2]
  18. while len(a) < 10:
  19.     a.append(2)
  20.        
  21. >>> from itertools import chain, islice, repeat
  22. >>> list(islice(chain(a, repeat(2)), 10))
  23. [1, 2, 2, 2, 2, 2, 2, 2, 2, 2]
clone this paste RAW Paste Data