Python: Rename duplicates in list with progressive numbers without sorting list

My solution with map and lambda: print map(lambda x: x[1] + str(mylist[:x[0]].count(x[1]) + 1) if mylist.count(x[1]) > 1 else x[1], enumerate(mylist)) More traditional form newlist = [] for i, v in enumerate(mylist): totalcount = mylist.count(v) count = mylist[:i].count(v) newlist.append(v + str(count + 1) if totalcount > 1 else v) And last one [v + str(mylist[:i].count(v) … Read more

SQL to select all rows with duplicate values in one column

You could use windowed COUNT: SELECT sub.name, sub.employee_id FROM (SELECT *, COUNT(*) OVER(PARTITION BY employee_id) AS c FROM users) AS sub WHERE c > 1; LiveDemo or simple IN: SELECT * FROM users WHERE employee_id IN (SELECT employee_id FROM users GROUP BY employee_id HAVING COUNT(employee_id) > 1); LiveDemo2 or correlated subquery: SELECT name, employee_id FROM … Read more

Replacing a HashSet Java member

Do a remove before each add: someSet.remove(myObject); someSet.add(myObject); The remove will remove any object that is equal to myObject. Alternatively, you can check the add result: if(!someSet.add(myObject)) { someSet.remove(myObject); someSet.add(myObject); } Which would be more efficient depends on how often you have collisions. If they are rare, the second form will usually do only one … Read more

Cloning a record in rails, is it possible to clone associations and deep copy?

You may get some good use out of the Amoeba gem for ActiveRecord 3.2. It supports easy and automatic recursive duplication of has_one, has_many and has_and_belongs_to_many associations, field preprocessing and a highly flexible and powerful configuration DSL that can be applied both to the model and on the fly. be sure to check out the … Read more

Robomongo : Exceeded memory limit for $group

{ allowDiskUse: true } Should be placed right after the aggregation pipeline. In your code this should go like this: db.getCollection(‘RAW_COLLECTION’).aggregate([ // Group on unique value storing _id values to array and count { “$group”: { “_id”: { RegisterNumber: “$RegisterNumber”, Region: “$Region” }, “ids”: { “$push”: “$_id” }, “count”: { “$sum”: 1 } }}, // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)