How to build a link based on a list of values?


Let’s say I have the following list in Python:

values = [sku1, sku2, sku3, sku4, sku5]

Based on list’s length, I need to add each value from the list to a link.
For example if the list has 1 item, my link should be:

link = '' + values[0]

If the list has 2 items, my link should be:

link = '' + values[0] + values[1]

..and so on.

I’ve tried doing this with:

if len(values) == 1:
      link = '' + values[0]
if len(values) == 2:
      link = '' + values[0] + values[1]

But the input list can have any number of items so using so many ifs doesn’t seem ok.
Is there any other way of doing this?


values = ["sku1", "sku2", "sku3", "sku4", "sku5"]
link = ''
for value in values:
    link += value
Answered By: Eftal Gezer
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.