for n in range(0, len(list1)-1)This is not Pythonic, instead it is better to use enumerate():
for index, item in enumerate(list1):On each iteration, "index" will be what you wanted "n" to be, and "item" will be an item from "list1".
You can see how it works with this:
for index, item in enumerate(list1): print(index, item)And the list assignment error happens because you start with an empty list (prefered_output) and append to an uninitiated index. Instead use list's .append() method.