美文网首页
Python学习笔记04——python入门编码技巧

Python学习笔记04——python入门编码技巧

作者: 远航天下 | 来源:发表于2018-07-25 14:51 被阅读0次
代码如下:
author = 'damao'

import itertools
from collections import Counter

# 字符串翻转
a = "My_Python"
print(a[::-1])

# 矩阵转置
a = [1,2,3,4]
b = ['l','o','v','e']
for x,y in zip(a,b):
    print(x,y)

# 将列表中的元素拆分成变量
a = ['l','o','v','e']
a,s,d,f = a
print(a,s,d,f)

# 字符串列表拼成一个字符串
a = ['I ','love',' you!']
print(''.join(a))

# 变量交换
a = 1
b = 2
a,b = b,a
print(a)
print(b)

# 不使用循环输出
print("damao"*5 + ' ' + 'good'*5)

# 不使用循环,将嵌套列表变成单个列表
a = [[1, 2], [3, 4], [5, 6]]
print(list(itertools.chain.from_iterable(a)))

# 检查一个单词和另一个单词是否只是字母顺序不同
def is_anagram(str1, str2):
    return Counter(str1) == Counter(str2)

if __name__=="main":
    is_anagram('abcd','dbca')
    is_anagram('abcd','dbaa')

# 从字符输入中获取值
result = map(lambda x: x +1,input([1,2,3,4]).split())
print(result)

相关文章

网友评论

      本文标题:Python学习笔记04——python入门编码技巧

      本文链接:https://www.haomeiwen.com/subject/nivpmftx.html