python Python备忘单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python备忘单相关的知识,希望对你有一定的参考价值。

res = a if a > b else b

# sorting dict elements to write to a file
with open('../stats/trips-per-week.txt', 'w') as outF:
    h_sorted = sorted(tripsPerWeek.items(), key=lambda x: x[0])
    for h in h_sorted:
        d_sorted = sorted(h[1].items(), key=lambda x: x[0])
        for d in d_sorted:
            outF.write(str(h[0]) + '\t' + str(d[0]) + '\t' + str(d[1]) + '\n')
            
# pretty writing to a file using pprint
outF.write(pprint.pformat(tripsPerWeek))

# skip first line in file
with open('data.csv', 'r') as f_in:
    next(f_in)
    for l in f_in:
        
# timer
runTime=(time.mktime(datetime.datetime.now().timetuple()))
print("Done in "+str(time.mktime(datetime.datetime.now().timetuple())-runTime)+" seconds")

# iterator — instead of large lists
(х*х for x in data) # general syntax
if any(number < 10 for number in numbers):  # will stop calculation if found first number < 10

# switch
keycode = 2
functions = {
    1: key_1_pressed,
    2: key_2_pressed,
    3: key_3_pressed}
functions.get(keycode, unknown_key_pressed)()   # includes default behavior

# nice way to return value if any
    return se.pool.extract_parsed_url(url).vhost or 'empty'
    
# nice way to calculate values and write result
def reduce_suggestions(groups):
    for key, records in groups:
        suggestions = Counter()
        for record in records:
            tag = MARKUP.get(record.target, UNKNOWN)
            suggestions[tag] += record.edge_weight
        dump = json.dumps(OrderedDict(suggestions.most_common())).replace('"',"'")

以上是关于python Python备忘单的主要内容,如果未能解决你的问题,请参考以下文章

python Python备忘单

python Codewars Python测试框架的备忘单

python Spark Dataframes的备忘单(使用Python)

python pyspark rdd备忘单

python pyspark sql备忘单

python 烧瓶登录备忘单