Basically, I am trying to join together the entries in a set in order to output one string. I am trying to use syntax similar to the join function for lists. Here is my attempt:
list = ["gathi-109","itcg-0932","mx1-35316"]
set_1 = set(list)
set_2 = set(["mx1-35316"])
set_3 = set_1 - set_2
print set_3.join(", ")
However I get this error: AttributeError: 'set' object has no attribute 'join'
What is the equivalent call for sets?
Nor the
set
nor thelist
has such methodjoin
, string has it:By the way you should not use name
list
for your variables. Give it alist_
,my_list
or some other name becauselist
is very often used python function.Set's do not have an order - so you may lose your order when you convert your list into a set, i.e.:
Generally the order will remain, but for large sets it almost certainly won't.
Finally, just incase people are wondering, you don't need a ', ' in the join.
Just: ''.join(set)
:)