我有一个清单L.
我可以删除元素i:
del L[i]
Run Code Online (Sandbox Code Playgroud)
但是,如果我有一组不连续的索引要删除怎么办?
I=set([i1, i2, i3,...])
Run Code Online (Sandbox Code Playgroud)
这样做:
for i in I:
del L[i]
Run Code Online (Sandbox Code Playgroud)
不行.
有任何想法吗?
有没有办法做array_map但作为迭代器?
例如:
foreach (new MapIterator($array, $function) as $value)
{
if ($value == $required)
break;
}
Run Code Online (Sandbox Code Playgroud)
这样做的原因是$ function很难计算,而$ array有太多的元素,只需要映射直到我找到一个特定的值.array_map将在我搜索我想要的值之前计算所有值.
我自己可以实现迭代器,但我想知道是否有本地方法来做到这一点.我找不到任何搜索PHP文档的东西.
如果我创建一个文件:
TEST.CPP:
void f(double **a) {
}
int main() {
double var[4][2];
f(var);
}
Run Code Online (Sandbox Code Playgroud)
然后运行:g ++ test.cpp -o test
我明白了
test.cpp: In function `int main()':
test.cpp:8: error: cannot convert `double (*)[2]' to `double**' for argument `1'
to `void f(double**)'
Run Code Online (Sandbox Code Playgroud)
为什么我不能这样做?
是不是double var [4] [2]和double**var一样然后分配内存?
我刚刚创建了以下模型:
class Categoria(models.Model):
nombre=models.CharField(max_length=30)
padre=models.ForeignKey('self', blank=True, null=True)
def __unicode__(self):
return self.nombre
Run Code Online (Sandbox Code Playgroud)
然后注册到管理界面和syncdb'd
如果我只添加纯ASCII字符,一切都OK.但如果我添加一个名为"á"的"类别"(说些什么),我会得到:
Environment:
Request Method: GET
Request URL: http://192.168.2.103:8000/administracion/locales/categoria/
Django Version: 1.1.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'cruzandoelsuquiaDJ.locales']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Template error:
In template /usr/lib/pymodules/python2.6/django/contrib/admin/templates/admin/change_list.html, error at line 78
Caught an exception while rendering: ('ascii', '\xc3\xa1', 0, 1, 'ordinal not in range(128)')
68 : {% endif %}
69 : {% endblock %}
70 :
71 : <form action="" method="post"{% if cl.formset.is_multipart %} …Run Code Online (Sandbox Code Playgroud) 有没有办法在初始化后修改wxPython上的StaticBoxSizer的标签?
我在wxPython的文档中找不到任何内容.
谢谢
我有一套功能:
functions=set(...)
Run Code Online (Sandbox Code Playgroud)
所有功能都需要一个参数x.
做python的最有效方法是做类似的事情:
for function in functions:
function(x)
Run Code Online (Sandbox Code Playgroud)