``If you can do exactly what you want with Python 3.x, great! There's a few downsides, such as comparatively limited library support and the fact that current Linux distributions and Macs are still shipping with 2.x by default, but as a language Python 3.x is definitely ready." - Python Official Website
They really go out of their way to try and apologize for a shitty language. 3.x is awful and NO ONE will ever adopt it. Python is going to die when 2.7 becomes too old to be useful since Python is just a novelty language that represent an idea that will actually be polished and efficient at some point down the road.
Name:
Anonymous2011-05-20 21:05
Lisp
uniq L -> L,sort,{[@A X X @B]->[@A @[X @B],r]; E->E}
Python
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)
Name:
Anonymous2011-05-20 21:05
Lisp:
Grammar -> split '| '(sentence -> (noun_phrase verb_phrase)
|noun_phrase -> (Article Noun)
|verb_phrase -> (Verb noun_phrase)
|Article -> the a
|Noun -> man ball woman table
|Verb -> hit took saw liked)
grammar = Dict(
S = [['NP','VP']],
NP = [['Art', 'N']],
VP = [['V', 'NP']],
Art = ['the', 'a'],
N = ['man', 'ball', 'woman', 'table'],
V = ['hit', 'took', 'saw', 'liked']
)
def generate(phrase):
"Generate a random sentence or phrase"
if isinstance(phrase, list):
return mappend(generate, phrase)
elif phrase in grammar:
return generate(choice(grammar[phrase]))
else: return [phrase]
def generate_tree(phrase):
"""Generate a random sentence or phrase,
with a complete parse tree."""
if isinstance(phrase, list):
return map(generate_tree, phrase)
elif phrase in grammar:
return [phrase] + generate_tree(choice(grammar[phrase]))
else: return [phrase]
def mappend(fn, list):
"Append the results of calling fn on each element of list."
return reduce(lambda x,y: x+y, map(fn, list))
C/C++
#include <stdio.h>
#include <stdlib.h>
#define p printf
#define r rand
char*g="foobarbaz";
char*h(){return(g+abs(r()%3)*3);}
int y(int v){for(int a=abs(r()%5)+3;a;z(++v),p(--a?", ":""));}
int z(int v){(r()%3==0&&v<=4||v==0)?p("%.3s(",h()),y(v),p(")"):p("%.3s",h());}
int main(){srand(time(0)),z(0);}
Python:
import sys,random
wordsL=3
words=['foo','bar','baz']
maxI=10
maxA=3
def shmjak(i):
j=random.randint(0,wordsL-1)
sys.stdout.write(words[j])
if i<=maxI:
k=random.randint(0,maxA)
sys.stdout.write('(')
for m in range(k-1):
shmjak(i+1)
sys.stdout.write(',')
shmjak(i+1)
sys.stdout.write(')')