Example 1: pbds in c++
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
int main()
{
new_data_set p;
p.insert(5);
p.insert(2);
p.insert(6);
p.insert(4);
cout << "The value at 3rd index ::"
<< *p.find_by_order(3) << endl;
cout << "The index of number 6::"
<< p.order_of_key(6) << endl;
cout << "The index of number seven ::"
<< p.order_of_key(7) << endl;
return 0;
}
Example 2: pbds in c++
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
ordered_set ord_set;
int a;
ord_set.insert(a);
*ord_set.find_by_order(a);
ord_set.order_of_key(a);
Example 3: how to find unique sublist in list in python
In [22]: lst = [[1,2,3],[1,2],[1,2,3],[2,3],[4,5],[2,3],[2,4],[4,2]]
In [23]: set(frozenset(item) for item in lst)
Out[23]:
set([frozenset([2, 4]),
frozenset([1, 2]),
frozenset([2, 3]),
frozenset([1, 2, 3]),
frozenset([4, 5])])
Example 4: how to create a break in iterating a sequence with a specific set of values in python
>>> d = {'foo': 1, 'bar': 2, 'baz': 3}
>>> for k, v in d.items():
... print('k =', k, ', v =', v)
...
k = foo , v = 1
k = bar , v = 2
k = baz , v = 3