- 1
- 2
- 3
- 4
- 5
cursor.execute(bla)
count = cursor.fetchone()
if count[0] > 0 or True:
cursor.execute(bla)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−178
cursor.execute(bla)
count = cursor.fetchone()
if count[0] > 0 or True:
cursor.execute(bla)
−102
def to_sk_pzd(text):
result = ''
for char in text:
for bit in str(bin(ord(char))):
if bit == '0':
result += 'сука'
elif bit == '1':
result += 'пиздец'
return result
print to_sk_pzd('чо нада?')
# Output:
# сукапиздецпиздецпиздецпиздецсукапиздецпиздецпиздецсукапиздецпиздецпиздецсукапиздецпиздецпиздецсукасукапиздецсукасукасукасукасукасукапиздецпиздецпиздецсукапиздецпиздецсукапиздецсукапиздецпиздецпиздецсукасукасукасукасукасукапиздецпиздецпиздецсукасукапиздецсукасукасукапиздецпиздецпиздецсукасукасукасукасукасукапиздецпиздецпиздецпиздецпиздецпиздец
гопник-байт-encoding
−87
#!/usr/bin/python
import itertools, math, os, random, re, sys
random.seed (1234)
while True:
s = sys.stdin.readline ().strip ()
if s == '':
s = sys.stdin.readline ().strip ()
if s == '':
break
t = sys.stdin.readline ()
r = sys.stdin.readline ()
s = [c for c in s]
t = [c for c in t]
r = [c for c in r]
s.sort ()
t.sort ()
r.sort ()
ok = True
for c in r:
if len (s) > 0 and c == s[0]:
s = s[1:]
elif len (t) > 0 and c == t[0]:
t = t[1:]
else:
ok = False
ok = ok and len (s) == 0 and len (t) == 0
if ok:
print 'YES'
else:
print 'NO'
#Люди делают так:
#a, b, c = (raw_input() for i in range(3))
#print 'YES' if sorted(a + b) == sorted(c) else 'NO'
Задача такая: даны три строки: a, b и c
проверить что третья может быть получена из двух других преремешиванием
Источник:
codeforces, Codeforces beta 101 round, 1018183
−89
def getResidueList():
resList = []
resList.append("366")
resList.append("367")
resList.append("368")
resList.append("369")
resList.append("370")
resList.append("371")
resList.append("372")
resList.append("373")
resList.append("374")
resList.append("375")
resList.append("376")
resList.append("377")
resList.append("378")
resList.append("379")
resList.append("380")
resList.append("381")
resList.append("382")
resList.append("383")
resList.append("384")
resList.append("385")
resList.append("386")
.... и так далее ...
resList.append("405")
resList.append("406")
resList.append("407")
resList.append("408")
resList.append("409")
resList.append("410")
resList.append("411")
resList.append("412")
resList.append("413")
resList.append("414")
... и так далее ....
resList.append("585")
resList.append("586")
resList.append("587")
resList.append("588")
resList.append("589")
return resList
Циклы? Не, не слышал
−86
def search_with_city(obj1, obj2, obj3):
print '------------Search by latitude, longitude and city------------'
list1 = []
list_new = []
while True:
line = file_airport.readline().lower()
if obj3 in line:
Str_file = ''.join(line)
List_file2 = Str_file.split(',')
if obj3 in List_file2[7]:
list1.append(List_file2)
for item in list1:
item.append(sqrt((float(item[11]) - float(obj1))**2 + (float(item[12]) - float(obj2))**2))
list_new = sorted(list1, key = lambda x: x[-1], reverse = False)
config = yaml.load(open('findairport.conf'))
outs = config['output']
for List_file in list_new:
if List_file2[3] != List_file[3]:
for out in outs:
out = out % dict(airportcode = str(List_file[0]).upper(), distance = List_file[-1],\
airportname = str(List_file[13]).title(), sa = str(List_file[8]).title(), street = str(List_file[10]).title(),\
city = str(List_file[7]).title(), state = str(List_file[5]).upper(), zip = List_file[3],\
country = str(List_file[2]).upper(), lat = str(List_file[11]), lon = str(List_file[12]+'\n'))
print out
if not line:
break
try:
if not obj1 in line and not obj2 in line and not obj3 in line:
print 'Nothing more is been found'
except:
pass
else:
pass
file_airport.seek(0)
PHP'шники наступают! :)
−89
def get_caller_module_dict(levels):
try:
raise RuntimeError
except RuntimeError:
e,b,t = sys.exc_info()
f = t.tb_frame
while levels > 0:
f = f.f_back
levels -= 1
ldict = f.f_globals.copy()
if f.f_globals != f.f_locals:
ldict.update(f.f_locals)
return ldict
−88
# класс ЧегоТоТамПарсер(object):
def _get_images(self, soup, basedomain):
soup = soup.get_soup()
fb_images = soup.findAll(name="meta", attrs={
"property": lambda property: property and property.lower() == "og:image"})
images = (soup.body or soup).findAll(name="img", src=True)
get_source = lambda img: img.get("content") \
if img.get("content", None) \
else img.get("src") \
if img.get("src").startswith("http://") \
else "http://"+img.get("src").lstrip("/") \
if img.get("src").startswith("//") \
else urljoin("http://"+basedomain, img.get("src").lstrip("/"))
return list(set(map(get_source, fb_images + images)))
def get_images(self):
try:
if self.basedomain:
return self._get_images(self.soup, self.basedomain)
return []
except URLError:
return []
над этим работало коллективное бессознательное
−85
TEMPLATES = ( # {'s': 0, 'm': 1, 'l': 2, 'xl': 3, 'xxl': 4}
((1, 0), _("1-z")), ((1, 1), _("1-z-a")),
((1, 2), _("1-z-a-p1")), ((2, 0), _("2-z")),
((2, 1), _("2-z-a")), ((2, 2), _("2-z-a-p2")),
((2, 3), _("2-z-a-p3")), ((3, 0), _("3-z")),
((3, 1), _("3-z-a")), ((3, 2), _("3-z-a-p1")),
((4, 0), _("4-z")), ((4, 1), _("4-z-a")),
((4, 2), _("4-z-a-p3")), ((4, 3), _("4-z-p3")),
((4, 4), _("4-p3")),)
это константа из описания класса формы, если кто-то еще не догадался
−100
class SomeThing(object)
def _get_value(self):
return #return some value
get_value = property(_get_value)
Декораторы? не не слышал.
−85
def __getattr__(self,name):
if name == '_creator':
return 'Article'
else:
raise AttributeError