Python 刷题知识点
Posted HannahGreen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 刷题知识点相关的知识,希望对你有一定的参考价值。
if : elif : else :
print(‘{0} {1} {2}‘ .format((a + b), (a - b), (a * b)))
print(*[num**2 for num in range(n)], sep = ‘ ‘)
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(‘ ‘.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() + " " 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 刷题知识点的主要内容,如果未能解决你的问题,请参考以下文章