Search result for 'django remove duplicates'
(0.0217971801758 seconds)
10 pages : « First ‹ Prev 1 2 3 4 5 6 7 8 9 10 Next › Last»

Nelson Hall/Remove Duplicates in an Array ( VB.NET)

 Private Function RemoveDupes(ByVal myArr As Array) As Array

        Dim i As Integer = 0
        Dim j As Integer = 0
        ' Creates and initializes a new Array 
        Dim myArr2 As [String]()
        Try
            ReDim myArr2(myArr.Length)

            ' Sorts the entire Array using the default comparer.
            Array.Sort(myArr)

            myArr2(0) = CType(myArr.GetValue(0), String)
            For i = 1 To myArr.Length - 1
                If (myArr2(j) <> CType(myArr.GetValue(i), String)) Then
                    j += 1
                    myArr2(j) = CType(myArr.GetValue(i), String)
                End If
            Next i
            ReDim Preserve myArr2(j)

            Return myArr2
        Catch ex As Exception
            MsgBox(ex, MsgBoxStyle.Critical)
        End Try

    End Function

When provided with an array containing duplicates this function will return an array with duplicates removed and sorted in ascending order.

Brian Davis/Remove duplicate files ( python)

import os, sys

# get checksums this may take a while
print "Collecting checksums..."
stdin, stdout = os.popen2("md5sum *.txt")
sums = stdout.readlines()

# sorting files
print "Sorting files..."
ls = {}
for s in sums:
	md5, file = s.split()
	# remove the stupid asterisk
	file = file[1:]
	if md5 in ls:
		ls[md5].append(file)
	else:
		ls[md5] = [file]
		
print "Deleting dupes..."
n = 0
for md5 in ls:
	for file in ls[md5][1:]:
		os.remove(file)
		n += 1
print "Operation complete. %d files removed." % n


A little script to remove duplicate files. Uses md5sum and a dictionary. There may be a shorter way to do it but this was simple. Works only on cygwin/Linux/Unix systems.

Tim Peters/Remove duplicates from a sequence ( python)

def unique(s):
    """Return a list of the elements in s, but without duplicates.

    For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3],
    unique("abcabc") some permutation of ["a", "b", "c"], and
    unique(([1, 2], [2, 3], [1, 2])) some permutation of
    [[2, 3], [1, 2]].

    For best speed, all sequence elements should be hashable.  Then
    unique() will usually work in linear time.

    If not possible, the sequence elements should enjoy a total
    ordering, and if list(s).sort() doesn't raise TypeError it's
    assumed that they do enjoy a total ordering.  Then unique() will
    usually work in O(N*log2(N)) time.

    If that's not possible either, the sequence elements must support
    equality-testing.  Then unique() will usually work in quadratic
    time.
    """

    n = len(s)
    if n == 0:
        return []

    # Try using a dict first, as that's the fastest and will usually
    # work.  If it doesn't work, it will usually fail quickly, so it
    # usually doesn't cost much to *try* it.  It requires that all the
    # sequence elements be hashable, and support equality comparison.
    u = {}
    try:
        for x in s:
            u[x] = 1
    except TypeError:
        del u  # move on to the next method
    else:
        return u.keys()

    # We can't hash all the elements.  Second fastest is to sort,
    # which brings the equal elements together; then duplicates are
    # easy to weed out in a single pass.
    # NOTE:  Python's list.sort() was designed to be efficient in the
    # presence of many duplicate elements.  This isn't true of all
    # sort functions in all languages or libraries, so this approach
    # is more effective in Python than it may be elsewhere.
    try:
        t = list(s)
        t.sort()
    except TypeError:
        del t  # move on to the next method
    else:
        assert n > 0
        last = t[0]
        lasti = i = 1
        while i < n:
            if t[i] != last:
                t[lasti] = last = t[i]
                lasti += 1
            i += 1
        return t[:lasti]

    # Brute force is all that's left.
    u = []
    for x in s:
        if x not in u:
            u.append(x)
    return u


The fastest way to remove duplicates from a sequence depends on some pretty subtle properties of the sequence elements, such as whether they're hashable, and whether they support full comparisons. The unique() function tries three methods, from fastest to slowest, letting runtime exceptions pick the best method available for the sequence at hand.

gerhardsletten/Remove duplicated lines with Perl ( Perl)

#!/usr/bin/perl
# Usage in command line: perl duplicate_remove.perl <file-to-be-convertet>
# Remove duplicated lines in text-files

my $origfile = $ARGV[0];
my $outfile  = "no_duplicates_" . $origfile; 
my %hTmp;
 
open (IN, "<$origfile")  or die "Couldn't open input file: $!"; 
open (OUT, ">$outfile") or die "Couldn't open output file: $!"; 
 
while (my $sLine = <IN>) {
  next if $sLine =~ m/^\s*$/;  #remove empty lines
                               #Without the above, still destroys empty lines except for the first one.
  print OUT $sLine unless ($hTmp{$sLine}++);
}
close OUT;
close IN;
print "The file $origfile is convertet! Look for $outfile in the same directory";

Name the source duplicateremove.perl and open Terminal.app in the same directory, and write: perl duplicateremove.perl

Abe/Remove Duplicate Rows ( PHP)

<?php
$duplicates = mysql_query("SELECT field1, field2, count(*) FROM table GROUP BY field1, field2 having count(*) > 1");
$count = mysql_num_rows($duplicates);
if ($count > 0) {
	while ($row = mysql_fetch_assoc($duplicates)) {
		$field = $row["field1"];
		$limit = $row["count(*)"] - 1;
		mysql_query("DELETE FROM table WHERE field1='$field' LIMIT $limit");
	}
	mysql_free_result($duplicates);
}
?>

$duplicates checks and groups duplicated rows with the same field1 and field2 (like comments maybe) and $limit counts how many times a row is duplicated.

abstraktor/remove duplicates from Relations ( Rails)

#app/models/user.rb
class User < ActiveRecord::Base
 has_many :adresses
end

#app/models/adress.rb
class Adress < ActiveRecord::Base
 belongs_to :user
end

#irb
User.first.adresses.map do |address|
 if liste.include? address
  address.destroy
 else
  liste.push address
 end
end

Remove all duplicate Adresses from first User.

keith/Remove Duplicate Numbers in an Array ( JavaScript)

var arr=[9, 7, 1, 9, 2, 3, 7, 4, 5, 4,7],
i,
arrayLength=arr.length,
out=[],
obj=[];

for (i=0; i < arrayLength; i++) {
   obj[arr[i]]=0;
}
  
for (i in obj) {
   out.push(i);
}
  
alert(out);

from this page: http://dreaminginjavascript.wordpress.com/2008/08/22/eliminating-duplicates/

RuslanSavenok/Remove Duplicate Characters ( JavaScript)

function removeDubCharacters (str) {
  var reg = /(.)\1{2,}/g;
  if(str.match(reg)) {
    str = str.replace(reg, '$1$1');
  }
  return str;
}

This function removes repeated characters after second one

sidneydekoning/Remove duplicates from Array ( ActionScript 3)

// removes all duplicate items from an array

/**
* @method removeDuplicates
* @description removes duplicate items from the array
* @param haystack:Array - the array from which to remove any duplicates
*/
public static function removeDuplicates(haystack:Array):Array{

	var dict:Dictionary = new Dictionary( true );
	var output:Array = new Array( );
	var item:*;
	var total:int = haystack.length;
	var pointer:int = 0;
	for(pointer; pointer < total ; pointer++) {
		item = haystack[pointer];
		if(dict[item] == undefined) {
			output.push( item );
			dict[item] = true;
		}
	}
	return output;     
}

blainejoubert/Remove Duplicate words in Array ( ActionScript 3)

private function removeDuplicates (a:Array){
					  
	o:for(var i = 0, n = a.length; i < n; i++){
              for(var x = 0, y = r.length; x < y; x++) {
			 if(r[x]==a[i]) continue o;
	       }
	      r[r.length] = a[i];
              }
		 return r;
					 
}

crypticsoft/Remove duplicate elements ( jQuery)

var seen = {};
        $('div.related div a').each(function() {
            var txt = $(this).text();
            if (seen[txt])
                $(this).remove();
            else
                seen[txt] = true;
        });

maxint/Remove duplicate item in a list ( Python)

a = [3, 3, 5, 7, 7, 5, 4, 2]
a = list(set(a)) # [2, 3, 4, 5, 7]

abelperez/Scala - Remove duplicates from List ( Scala)

object ListUtil
{
  def dedupe(elements:List[String]):List[String] = {
    if (elements.isEmpty)
      elements
    else
      elements.head :: dedupe(for (x <- elements.tail if x != elements.head) yield x)
  }
}

// example usage:
ListUtil.dedupe(List("one", "two", "one")).foreach(println)

Recursively remove duplicate elements from a List

chrisaiv/AS3: Remove Duplicates in an Array ( ActionScript 3)

function removeDuplicate(arr:Array) : void{
    var i:int;
    var j: int;
    for (i = 0; i < arr.length - 1; i++){
        for (j = i + 1; j < arr.length; j++){
            if (arr[i] === arr[j]){
                arr.splice(j, 1);
            }
        }
    }
}

var arr:Array = new Array("a", "b", "a", "c", "d", "b");
removeDuplicate(arr);

I found this awesome function that allows you to easily remove duplicate values.

romech/Remove duplicating Points from Array ( ActionScript 3)

function removeDuplicates (input:Array):Array
{
	var unique:Array = new Array();
	testLoop:for (var l:uint = 0; l < input.length; l++)
	{
		for (var m:uint = 0; m < unique.length; m++)
		{
			if ((input[l] as Point).equals(unique[m]))
			{
				continue testLoop;
			}
		}
		unique.push(input[l]);
	}
	return unique;
}

Removes duplicating elements from Array, containing only objects of Point class