Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

append set to another set

Tags:

c++

insert

set

Is there a better way of appending a set to another set than iterating through each element ?

i have :

set<string> foo ; set<string> bar ;  .....  for (set<string>::const_iterator p = foo.begin( );p != foo.end( ); ++p)     bar.insert(*p); 

Is there a more efficient way to do this ?

like image 215
mr.bio Avatar asked Apr 09 '10 12:04

mr.bio


People also ask

Can we append a set to a set?

Note: Since set elements must be hashable, and lists are considered mutable, you cannot add a list to a set. You also cannot add other sets to a set.

How do you add one set to another in Python?

set add() in python The set add() method adds a given element to a set if the element is not present in the set. Syntax: set. add(elem) The add() method doesn't add an element to the set if it's already present in it otherwise it will get added to the set.

Can we append two sets in Python?

Sets can be joined in Python in a number of different ways. For instance, update() adds all the elements of one set to the other. Similarly, union() combines all the elements of the two sets and returns them in a new set.

How do I combine two sets in pandas?

The concat() function in pandas is used to append either columns or rows from one DataFrame to another. The concat() function does all the heavy lifting of performing concatenation operations along an axis while performing optional set logic (union or intersection) of the indexes (if any) on the other axes.


1 Answers

You can insert a range:

bar.insert(foo.begin(), foo.end()); 
like image 134
CB Bailey Avatar answered Oct 19 '22 04:10

CB Bailey