Tricks Learned in Codewars [Python]

Sep 29, 2016 21:02 · 72 words · 1 minute read Python Codewars

Tricks learned in CodeWars —— Python

A string’s reverse

How to reverse a string as quickly as possible?

The answer is [::-1].


>>> string = '1234567890'
>>> string[::-1]

Prefill an Array

Prefill an Array with a fixed value without loop.

def prefill(n,v=None):
        return [v]*int(n)
    except Exception as e:
        raise TypeError('%s is invalid' % n)

True without return

This is easy.

solve = lambda : True

Waiting for new stuff…