## 1. 交换变量值

```a, b = 5, 10
print(a, b)   //5, 10
a, b = b, a
print(a, b)   //10, 5
```

## 2. 将列表中所有元素组合成字符串

```a = ["python", "java", "c++", "go"]
print(",".join(a))  //python,java,c++,go```

## 3. 查找列表中频率最高的值

```a = [1, 1, 1, 2, 3, 3, 3, 3, 4, 4, 4]
print(max(set(a), key = a.count))```

## 4. 检查两个字符串是不是由相同字母打乱顺序组成

```from collections import Counter

a = "abcdefg"
print(Counter(a) == Counter(b))
```

## 5. 反转字符串、列表

```a = "dadabjdnakdmnkafad"
print(a[::-1])

num = 1343453535
print(int(str(num)[::-1]))

a = [1,3,554,64,2]
print(a[::-1])
```

## 6. 转置二维数组

```origin = [["a", "b"], ["c", "d"], ["e", "f"]]
transposed = zip(*origin)
print(list(transposed ))
```

## 7. 链式比较

```b = 6
print(4 < b < 7)
print(1 == b < 9)
```

## 8. 三元运算符

```b = "B"
c = "C"
flag = True
a = b if flag else c
```

## 9.链式函数调用

```def product(a, b):
return a * b

return a + b

b = True
print((product if b else add)(5 ,7))
```

## 10. for-else 语法

```a = [1, 2, 3, 4, 5]
for el in a:
if(el == 0)
print("找到 0 了")
else:
print("没有找到 0")
```

## 11. 合并字典

```d1 = {"a": 1}
d2 = {"b": 2}

print(**d1, **d2)  # python3.5支持

print(dict(d1.items() | d2.items()))

d1.update(d2)
print(d1)
```

## 12. 移除列表中重复元素

```items = [2,2,3,4,1]
print(list(set(items)))
```

## 13. **kwargs

```dictionary = {"a": 1, "b": 2}

def func(**kwargs)
for key in kwargs:
print("key:", key, "value:",kwargs[key])
```

## 14. 列表推导式

```numbers = [1, 2, 3, 4, 5, 6]
y = [x for x in numbers if x % 2 == 0]
print(y)   //[2, 4, 6]
```

## 15. map函数

```x = [1, 2, 3]
y = map(lambda x : x + 1 , x)
print(y)  //[2, 3, 4]
```