If you're using Python 3.6 an up, you can use f-strings if you like:
a = [1, 2, 3, 4]
result = f"a{a[0]}\ta{a[3]}\ta{a[1]}\ta{a[2]}"
print(result)
but it's not very extensible if a
ever changes it's dimensions.
If the order didn't matter I'd be more inclined to do something more along the lines of:
a = [1, 2, 3, 4]
result = "\t".join(f"a{x}" for x in a)
print(result)
This uses a comprehension to create a sequence of strings formatted the way you want, then join them together with tabs.
If order (or only selecting certain items) is important, but you still wanted to use something like this, you could try:
a = [1, 2, 3, 4]
indexes = [0, 3, 1, 2]
result = "\t".join(f"a{a[i]}" for i in indexes)
print(result)
That way you can change the size of a
, or the order you want just by changing those lists and the code will "just work" (presuming that you don't go outside the bounds of the list). So if you wanted to just print indexes 2 and 3:
a = [1, 2, 3, 4]
indexes = [2, 3]
result = "\t".join(f"a{a[i]}" for i in indexes)
print(result)