[Python] The meaning of list(map(int,input().split())) in Python3

list(map(int,input().split()))

a = list(map(int, input().split()))
# 创建一个列表,使用 split() 函数进行分割
# map() 函数根据提供的函数对指定序列做映射,就是转化为int型

map()

Description
map() will map the specified sequence according to the provided function.

The first parameter function calls the function function with each element in the parameter sequence, and returns a new list containing the return value of each function function.

Syntax
map() function syntax:

map(function, iterable, …)

>>> def square(x) :         # 计算平方数
...     return x ** 2
...
>>> map(square, [1,2,3,4,5])    # 计算列表各个元素的平方
<map object at 0x100d3d550>     # 返回迭代器
>>> list(map(square, [1,2,3,4,5]))   # 使用 list() 转换为列表
[1, 4, 9, 16, 25]
>>> list(map(lambda x: x ** 2, [1, 2, 3, 4, 5]))   # 使用 lambda 匿名函数
[1, 4, 9, 16, 25]
>>>

input().split()

username, passwd = input("用户名,密码:").split()   
# 注意input() 的返回类型是str
print(username,passwd)

result

用户名,密码:hong 123
hong 123

example

'''
小明和我参加班长的选举投票,投票人数为n,每人可以投K票,
第一行输入为投票人数,第二行输入为每个人投给小明的票数求保证我能获胜最小的K。
例如下面的示例,由于小明获得1+1+1+5+1=9票,则我获得4+4+4+0+4=12票,我获胜,此时5最小。
输入:
5
1 1 1 5 1
输出:
5
'''
n = int(input())
a = list(map(int, input().split()))
sum = 0
ans = 0
for i in a:
 if i>ans:
     ans = i
 sum+=i
while((ans*n-sum)<=sum):
 ans+=1
print(ans)

Guess you like

Origin blog.csdn.net/m0_37882192/article/details/115328761