To get rid of duplicates and preserve the order of occurrence, you need to append values "manually":
s = "We have a collection of types {}."
lst = [s1,s2,s3,s4]
fin = []
for x in lst:
if x not in fin:
fin.append(x)
print(s.format(", ".join(fin)))
See this Python demo
If you were not going to preserve the order, you might use set
that would return unique items in a list (just create a list from your variables):
s1 = 'Foo'
s2 = 'Boo'
s3 = 'Foo'
s4 = 'Duh'
print("We have a collection of types {}.".format(", ".join(set([s1,s2,s3,s4]))))
where:
"We have a collection of types {}.".format()
is the string format method where the string literal contains a {}
that is a placeholder for the only argument passed to the format
method
", ".join()
- a method to make a string out of a list joining the items with a comma+space
set()
- a method that takes an iterable and returns a frozenset, unique items in the iterable
[s1,s2,s3,s4]
- a list created from the standalone vars
See Python demo