码迷,mamicode.com
首页 > 编程语言 > 详细

Python 刷题知识点

时间:2019-12-19 09:45:42      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:comm   code   mst   pen   scores   style   split   numpy   字符   

if :
    elif :
else :
print({0} \n{1} \n{2} .format((a + b), (a - b), (a * b)))
print(*[num**2 for num in range(n)], sep = \n)
def f():
    return condition # 直接返回判断的条件真或假
print(*range(1, int(input())+1), sep= ‘‘)
x, y, z, n = (int(input()) for _ in range(4))
print ([a, b, c] for a in range(0, x+1) for b in range(0, y+1) for c in range(0, z+1) if a + b + c != n])
i = int(input())
lis = list(map(int,raw_input().strip().split()))[:i]
z = max(lis)
while max(lis) == z:
    lis.remove(max(lis))

print max(lis)
n = int(input())
marksheet = [[input(), float(input())] for _ in range(n)]
second_highest = sorted(list(set([marks for name, marks in marksheet])))[1]
print(\n.join([a for a,b in sorted(marksheet) if b == second_highest]))
if __name__ == __main__:
    n = int(input())
    student_marks = {}
    for _ in range(n):
        name, *line = input().split()
        scores = list(map(float, line))
        student_marks[name] = scores
    query_name = input()
    query_scores = student_marks[query_name]
    print("{0:.2f}".format(sum(query_scores) / (len(query_scores))))
L = []
for _ in range(0, int(input())):
    user_input = input().split( )
    command = user_input.pop(0)
    if len(user_input) > 0:
        if insert == command:
            eval("L.{0}({1}, {2})".format(command, user_input[0], user_input[1]))
        else:
            eval("L.{0}({1})".format(command, user_input[0]))
    elif command == print:
        print(L)
    else:
        eval("L.{0}()".format(command))
# eval() 将insert, pop, print等str转换成命令字符,进行执行
print raw_input() == 0 or hash(tuple(map(int, raw_input().split( ))))
def swap_case(s):
    return s.swapcase() # 字母大小写转换函数

if __name__ == __main__:
    s = input()
    result = swap_case(s)
    print(result)
def split_and_join(line):
    return "-".join(line.split(" ")) # 先分隔在用符号代替

if __name__ == __main__:
    line = input()
    result = split_and_join(line)
    print(result)
import sys
import xml.etree.ElementTree as etree

def get_attr_number(node):
    return sum([len(elem.items()) for elem in tree.iter()])

if __name__ == __main__:
    sys.stdin.readline()
    xml = sys.stdin.read()
    tree = etree.ElementTree(etree.fromstring(xml))
    root = tree.getroot()
    print(get_attr_number(root))
import xml.etree.ElementTree as etree

maxdepth = 0
def depth(elem, level):
    global maxdepth
    level += 1
    if level >= maxdepth:
        maxdepth = level
    for child in elem:
        depth(child, level)

if __name__ == __main__:
    n = int(input())
    xml = ""
    for i in range(n):
        xml =  xml + input() + "\n"
    tree = etree.ElementTree(etree.fromstring(xml))
    depth(tree.getroot(), -1)
    print(maxdepth)
import re

n, m = map(int, input().split())
a, b = [], ""
for _ in range(n):
    a.append(input())

for z in zip(*a):
    b += "".join(z)

print(re.sub(r"(?<=\w)([^\w]+)(?=\w)", " ", b))
import numpy as np
print(np.array(input().split(),int).reshape(3,3))
n, m = map(int, input().split())
array = numpy.array([input().strip().split() for _ in range(n)], int)
print (array.transpose())
print (array.flatten())
import numpy as np
a, b, c = map(int,input().split())
arrA = np.array([input().split() for _ in range(a)],int)
arrB = np.array([input().split() for _ in range(b)],int)
print(np.concatenate((arrA, arrB), axis = 0))

Python 刷题知识点

标签:comm   code   mst   pen   scores   style   split   numpy   字符   

原文地址:https://www.cnblogs.com/HannahGreen/p/12065777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!