Use list concatenation rather than append.