bundle exec jekyll serve
字符串不存在原地反转这种操作,因为字符串是不可变的!!! list是可变的,所以list可以原地反转。
# a is a list
a[:] = a[::-1]
import os
here = os.path.dirname(os.path.abspath(__file__))
参考:
https://stackoverflow.com/questions/21957131/python-not-finding-file-in-the-same-directory
https://stackoverflow.com/questions/1315390/python-find-a-file-in-the-same-directory
lst = [[0, 1], [0, 4], [1, 0], [4, 0]]
data = {tuple(item) for item in map(sorted, lst)} # method 1
data = {tuple(sorted(item)) for item in lst} # method 2
Type 1:
from itertools import tee
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return zip(a, b)
sudo python3.6 -m pip install --upgrade pip
sudo python3.6 -m pip install [package_name]
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt update
sudo apt install python3.6
Removal of Tuple Parameter Unpacking
zs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50)]
# t1 = map(lambda (x, y): x+y, zs) # python2 only
t1 = map(lambda tup: tup[0]+tup[1], zs) # python2 & python3
t2 = list(t1)
print(t2)
# def fxn(a, b_c, d): # b_c is (b,c) 2to3 refactoring tool
flatten = lambda x: [y for l in x for y in flatten(l)] if type(x) is list else [x]
# Below is for you to understand
# flatten = lambda x: [item for items in itemss for item in flatten(items)] if type(itemss) is list else [itemss]
>>> a = [1, 2, [3, 4], [[5, 6], [7, 8]]]
>>> flatten(a)
[1,2,3,4,5,6,7,8]
from collections import Counter
l1 = "I have a dog and a cat sally."
l2 = "Why the fuck I have a dog and a cat cat."
# should output "5:why the fuck cat sally"
l1 = l1.split()
l2 = l2.split()
OlderNewer