Looking to join two set as an append without sorting.
Here is my code:
a = {123,456,789}
b = {777,888}
a = a.union(b)
a
Output:
{123, 456, 777, 789, 888}
Desired output:
{123, 456, 789, 777, 888}
Thanks!
Looking to join two set as an append without sorting.
Here is my code:
a = {123,456,789}
b = {777,888}
a = a.union(b)
a
Output:
{123, 456, 777, 789, 888}
Desired output:
{123, 456, 789, 777, 888}
Thanks!
Sets are unordered so you can't guarantee an arrangement. The answer from BEN_YO will make it so the second sets elements are at the end but the internal ordering will differ, as shown in his sample output.
If ordering matters you need to use a different collection type. A quick hack if you want both ordering and uniqueness would be to use a dictionary, as in modern python dictionary keys are ordered and unique.
a = {123: '',456: '',789: ''}
b = {777: '',888: ''}
a = {**a, **b}
Although then you can't use faster merge operations like union so it may not be an ideal solution.
If we need the order
a = {123,456,789}
b = {777,888}
a = list(a)+[i for i in b if i not in a]
a
Out[58]: [456, 123, 789, 888, 777]
panda
method unique
pd.Series(list(a)).append(pd.Series(list(b))).unique()
Out[66]: array([456, 123, 789, 888, 777], dtype=int64)