I'm working on a project right now and as one of the features, I'm supposed to traverse through a list and output the items in different lines.
The code looks something like this:
dictionary = {'key0': sorted([item + "\n"
for item in mylist}])
print(x[1]) for x in dictionary.items()
However, this leaves a trailing newline every time.
Would something like this work?
string = ''
otherlist = sorted([item + "\n" for item in mylist])
for i in range(len(otherlist)):
string.join(sorted[i])
string.rstrip()
print(string)
Are there any better ways to do this?