Skip to main content
Update code with plots.
Source Link
Peilonrayz
  • 44.6k
  • 7
  • 80
  • 158

The best solution is to use str.join()str.join(), using ', ' as the joining string.

def display(flavours):
    print(', '.join(flavours) + '.')

Outputting:

>>> display(['chocolate', 'vanilla', 'caramel', 'strawberry', 'coffee'])
chocolate, vanilla, caramel, strawberry, coffee.

Comparing this to the two adaptions of my approach, and against AJNeufeld in one of the graphs:

image

image

NOTE: Code to plot the graphs, complete changes.

The best solution is to use str.join(), using ', ' as the joining string.

print(', '.join(flavours) + '.')

The best solution is to use str.join(), using ', ' as the joining string.

def display(flavours):
    print(', '.join(flavours) + '.')

Outputting:

>>> display(['chocolate', 'vanilla', 'caramel', 'strawberry', 'coffee'])
chocolate, vanilla, caramel, strawberry, coffee.

Comparing this to the two adaptions of my approach, and against AJNeufeld in one of the graphs:

image

image

NOTE: Code to plot the graphs, complete changes.

Source Link
Peilonrayz
  • 44.6k
  • 7
  • 80
  • 158

The best solution is to use str.join(), using ', ' as the joining string.

print(', '.join(flavours) + '.')