我正在尝试将地图转换为列表,但它返回了TypeError: 'int' object is not callable。有人能跟我解释一下吗?
n = int(input())
arr = list(map(n, input().split()))
for i in arr:
print(i)
错误:
arr = list(map(n, input().split()))
TypeError: 'int' object is not callable
from django import forms
class SignUpForm(forms.Form):
birth_day = forms.ChoiceField(choices=range(1,32))
我得到“渲染时捕获TypeError:'int‘对象不可迭代”。说,choices参数接受列表或元组等可迭代变量。
说range()创建一个列表。
为什么我得到一个错误?
我尝试使用map()将列表转换为str,但收到了不同的错误。
我需要帮助找出如何通过此BiFunction
BiFunction<Integer, List<Integer>, Integer> func = (a, b) -> {
int result = 0;
int temp = 0;
for(Integer ele : b) {
temp = b.get(ele);
result += temp;
}
return a + result;
};
我正在使用这个junit测试。
voi
该程序的目标是询问用户在3天(周末)的衣服驾驶中每天收集多少件衣服,平均起来,第二个周末再做一次,然后平均两个周末(每天的衣服)。
这是我的代码:
import math
num_clothes = int()
weekend_total = int()
weekend_avg = float()
total_clothes = int()
total_avg = float()
index = int()
index = 1
while index <= 2:
index = 1
while index <= 3:
num_
我第一次在Python中尝试多线程。我看到了。下面是我的示例代码
from multiprocessing.dummy import Pool as ThreadPool
pool = ThreadPool(4)
mylist = [3,4,5,6,7,8, ..., 5]
results = pool.map(my_method, my_list) # from docs it is clear that pool.map takes method and argument as a list
def my_method(mylist):
data = []
for i
我有一个包含两个数字列表的元组- (1,2,3,4,5,6,7,8)
我需要将每个列表中相应的数字对相加。ie (1+5),(2+6)等。输出一个列表如6,8,10,12。它也应该适用于列表中的任何数量的元素(2个5的列表,2个6的列表等)。
我一直在尝试一个使用"map sum .transpose“的函数,但是似乎不能得到正确的类型(因为它在一个元组中)。我在这里找到了一段代码,它适用于列表列表,但不知道如何对列表元组执行相同的操作(可能吗?)。当我尝试更改"a“的类型或使用Int时,我编译为类型不匹配错误。
tupSums :: Num a => [[a]] -&g
这段代码在gcc 4.6.1和4.8.1中编译时没有错误( eclipse自动编译表明:候选对象是: float pow(float,int) long double pow(long double,int) double pow(double,int) ):
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(void) {
const int i = 0, x = 2;
double y = pow( i, x );
我对列表理解在将文件读取为csv或json文件时的使用有疑问。在第一段代码中,我使用普通的长方法来获取一行的值,并将其附加到一个空列表的末尾。正如预期的那样,这工作得很好,没有任何问题:
with open("file.csv") as W_F:
reader = csv.reader(W_F)
header = next(reader)
brightness,lons,lats=[], [], []
for row in reader:
bright=float(row[2])
brightness.app
在Python3中,我试图找出关于减()和函数作为函数参数的方法,或者更好地将一个函数作为另一个函数的参数传递,如果第一个参数不是显式的,请参见下面的
给予:
# define a function `call` where you provide the function and the arguments
def call(y,f):
return f(y)
# define a function that returns the square
square = lambda x : x*x
# define a function that returns the increm
import java.util.*;
public class MyClass {
public static void main(String args[]) {
int[] arr = new int[]{2,3,4,5};
int[] min = new int[]{Integer.MAX_VALUE};
int tgt = 7;
List<Integer> lst = new ArrayList<>();
List<Integer> sol = new A
因此,我在python中编写了这个简单的程序,它的函数名为num,函数以两个参数作为整数,并检查其中是否存在"20“,如果是,则返回True,否则返回False,您会注意到,在if语句中,我调用了另一个函数sum,它是python中内置的函数,所以当我试图传递函数中的a和b的值而不将它们作为元组传递时,它会给出下面提到的错误。所以我的问题是,当我像这个sum((a,b))而不是这个sum(a,b)传递它们时,它为什么会工作呢?
File "c.py", line 8, in <module>
print(num(220,10))
File
在我的编程经验中,我以前并没有真正使用过maps,所以我在理解更多的complex versions of maps时遇到了困难。因此,假设问题是给定了一个以分钟为单位的整数,在本例中为n = 808。你要做的就是把这个数字转换成24 hour time,所以是hh:mm。这将为您提供13:28。完成此操作后,将该时间的位数相加即可得到答案。所以,answer would be 14。我看到了这个解决方案的一个非常好的一行,我正在努力理解它,因为我的解决方案是关于5 more lines of code的。
这就是解决方案:
sum(map(int, str(n // 60 * 100 + n
我想写一个函数,它接受一个int或一个int列表作为参数,并处理这些值。
大概是这样的:
def func(input):
if isinstance(input, int):
print(input)
else:
for i in input:
print(i)
对我来说,这看起来不是很好,但我不知道如何做得更好。有没有办法在int上“循环”,或者把int“打包”到一个处理这两个选项的列表中?
谢谢
当将列表传递给函数时,我遇到了问题。它似乎对list变量具有全局影响,但在我的函数中并没有声明它是全局的。有人能告诉我发生了什么以及如何解决这个问题吗?
def a_Minus_b(a,b):
for i in range(len(b)):
print("a= ", a)
if b[i] in a:
a.remove(b[i])
return a
x = [1,2,3,4]
a_Minus_b(x,x)
a= [1, 2, 3, 4]
a= [2, 3, 4]
a= [2, 4]
错误:
Trace
我正在尝试使用python包异步获取一个URL列表,类似于使用Python3.6.5和requests_html 0.10.0的。
我的理解是,AsyncHTMLSession.run()应该与asyncio.gather()一样工作:您给它一堆可等待的东西,并且它们都运行。这不对吗?
下面是我正在尝试的代码,我希望它能得到页面并存储响应:
from requests_html import AsyncHTMLSession
async def get_link(url):
r = await asession.get(url)
return r
asession = As