# 如何用python填充0

``a = ['a','b','c'] b = [0,0,0,0,0,0,0,0,0,0]` `

` `a=['a','b','c'] b = [0 for i in range(5)] b = [a[i] for i in b if a[i] else i] print a` `

` ` File "c.py", line 7 b = [a[i] for i in b if a[i] else i] ^ SyntaxError: invalid syntax` `

` `a = a + [0]*(maxLen - len(a))` `

` `>>> from itertools import repeat >>> a + list(repeat(0, 6)) ['a', 'b', 'c', 0, 0, 0, 0, 0, 0]` `

` `c = (a + b)[:len(b)]` `

` `a = ['a','b','c'] b = [0,0,0,0,0,0,0,0] c = a + b #= ['a','b','c',0,0,0,0,0,0,0]` `
` `a+[0]*(len(b) - len(a)) ['a', 'b', 'c', 0, 0, 0, 0, 0, 0, 0]` `

` `map(lambda x: {}, [None] * n)` `

` `>>> map(lambda x: {}, [None] * 14) [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}] >>> l = map(lambda x: {}, [None] * 14) >>> l[0] {} >>> l[0]['bar'] = 'foo' >>> l [{'bar': 'foo'}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]` `

` `a + b[len(a):]` `

` `>>> a = ['a', ['b'], None, False] >>> b = [0, 1, 2, 3, 4, 5] >>> a + b[len(a):] ['a', ['b'], None, False, 4, 5]` `

` `>>> a = ['a', ['b'], None, False] >>> b = [0, 1, 2] >>> (a + b[len(a):])[:len(b)] ['a', ['b'], None]` `
` `LIST_LENGTH = 10 a = ['a','b','c'] while len(a) < LIST_LENGTH: a.append(0)` `

` `a = ['a', 'b', 'c'] maxlen = 10 result = [(0 if i+1 > len(a) else a[i]) for i in range(maxlen)]` `