- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
a=[1,4,6,3,4,5,6,6,7,7,9,9,4,3,4,7,7,7,4,3,5,7,3,6,3,]
print a
def removeDoubles(a):
nonD=range(len(a))
for i in range(len(a)):
for j in range(i+1,len(a)):
if a[i]==a[j]:
nonD.remove(i)
break
b=[]
for i in nonD:
b.append(a[i])
return b
def removeDoubles2(a):
#b=sorted(a)
def quickSort(a):
def qSort(i,j):
global a
if j==i:
return
elif j-i==1:
if a[i]>a[j]:
c=a[j]
a[j]=a[i]
a[i]=c
return
else:
l=(j+i)/2
qSort(i,l)
qSort(l+1,j)
join(i,l,j)
return
def join(i,l,j):
global a
k=i
n=l+1
m=0
s=j
t=l
b=range(j-i+1)
while 1:
if a[k]<a[n]:
z=k
k=n
n=z
z=s
s=t
t=z
b[m]=a[n]
m+=1
n+=1
if n>s:
for g in range(t-k+1):
b[m+g]=a[k+g]
break
for g in range(j-i+1):
a[i+g]=b[g]
qSort(0,len(a)-1)
c=a
quickSort(c)
b=[]
b.append(c[0])
for i in range(1,len(c)):
if c[i]>c[i-1]:
b.append(c[i])
return b
print removeDoubles(a)
print removeDoubles2(a)
Удаление дублей из массива. Взято отсюда:
http://www.0chan.ru/c/res/181489.html