This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
def trunc(s, limit, coding="UTF-8", postfix="..."): | |
''' | |
works both on python2 and python3 | |
''' | |
unicode_s = s.decode(coding) if type(s) == bytes else s | |
nums = (len(u.encode(coding)) for u in unicode_s) | |
sum, i = 0, 0 | |
use_postfix = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
class ColaDrinker(object): | |
def __init__(self, money, cola_price, redeem_num): | |
self.cola_price = cola_price | |
self.redeem_num = redeem_num | |
self.bottles = 0 | |
self.money = money |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
quicksort = lambda l: quicksort([i for i in l[1:] if i < l[0]]) + [l[0]] + quicksort([j for j in l[1:] if j >= l[0]]) if l else [] | |
## but readability counts | |
# def quicksort(l): | |
# if not l: return [] | |
# pivot = l.pop() | |
# less = [i for i in l if i < pivot] | |
# greater = [j for j in l if j >= pivot] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* rely on underscore | |
*/ | |
// ============ imperative ============ | |
function fizzbuzz(arr) { | |
var i = 0, | |
len = arr.length, | |
curr = null; | |
for (; i < len; i++) { |
NewerOlder