python fixed string size
python, string
Solution
Use a list.
n = 10
i = 2
mylist = ["0"] * n
mylist[i-1] = "1"
print " ".join(mylist)
Problem
Suppose I need a n elements long with each element seperated by a space. Further, I need the ith element to be a `1` and the rest to be a `0`. What's the easiest pythonic way to do this? Thus if `n = 10`, and `i = 2`, I would want `0 1 0 0 0 0 0 0 0 0` I want something like a `new string[]` that you can get in C++ but the Python version is eluding me. Thanks!