我的问题很简单:我有一个很长的元素列表,我想迭代并根据条件检查每个元素.根据条件的结果,我想删除列表的当前元素,并像往常一样继续迭代它.
我已经在这个问题上阅读了其他几个主题.提出两种解决方案.要么从列表中创建一个字典(这意味着要复制已经填满我所有RAM的所有数据).要么反向走列表(这打破了我想要实现的算法的概念).
有没有更好或更优雅的方式呢?
def walk_list(list_of_g):
g_index = 0
while g_index < len(list_of_g):
g_current = list_of_g[g_index]
if subtle_condition(g_current):
list_of_g.pop(g_index)
else:
g_index = g_index + 1
Run Code Online (Sandbox Code Playgroud) 我知道非阻塞接收在消息传递中没有被使用,但仍有一些直觉告诉我,它是必需的.以GUI事件驱动的应用程序为例,您需要某种方式以非阻塞方式等待消息,因此您的程序可以执行一些计算.解决此问题的方法之一是使用带有消息队列的特殊线程.是否有一些用例,即使你有线程,你真的需要非阻塞接收?
我们可以使用sql找到msaccess中的所有表.
和我们在sqlserver中一样
select * from sys.tables
Run Code Online (Sandbox Code Playgroud)
在sqlite中
SELECT * FROM sqlite_master where type='table'
Run Code Online (Sandbox Code Playgroud) 我有很多非常长的数组.没有运行时排序是可能的.手动排序也很耗时.此外,可以在以后以任何顺序添加新元素,因此我想使用C预处理器按值对它们进行排序,或者可能有任何编译器标志(GCC)?
例如:
sometype S[] = {
{somevals, "BOB", someothervals},
{somevals, "ALICE", someothervals},
{somevals, "TIM", someothervals},
}
Run Code Online (Sandbox Code Playgroud)
必须这样排序:
sometype S[] = {
{somevals, "ALICE", someothervals},
{somevals, "BOB", someothervals},
{somevals, "TIM", someothervals},
}
Run Code Online (Sandbox Code Playgroud)
好的,这是我的解决方案:
sort -b -i --key=2 tobesorted.c实际上,有一种可能性直接从预处理器调用"排序"会很好(我希望至少GCC能以某种方式支持这些功能,但似乎它没有).
当与请求一起发送时,查询字符串参数是否在HTTPS中加密?
我正在使用我的UIScrollview来扩展底层的UIImageView.在我的视图控制器中我设置
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return myImageView;
}
Run Code Online (Sandbox Code Playgroud)
在viewDidLoad方法中,我尝试将zoomScale设置为2,如下所示(注意在Interface Builder中设置了UIImageView和Image):
- (void)viewDidLoad {
[super viewDidLoad];
myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
myScrollView.contentOffset = CGPointMake(941.0, 990.0);
myScrollView.minimumZoomScale = 0.1;
myScrollView.maximumZoomScale = 10.0;
myScrollView.zoomScale = 0.7;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
NSLog(@"zoomScale: %.1f, minZoolScale: %.3f", myScrollView.zoomScale, myScrollView.minimumZoomScale);
}
Run Code Online (Sandbox Code Playgroud)
我尝试了一些这方面的变体,但NSLog总是显示1.0的zoomScale.
我把这个搞砸了的想法?
有几种方法可以为测试生成数据(不仅仅是单元测试),例如,Object Mother,构建器等.另一种有用的方法是将测试数据写为纯文本:
Run Code Online (Sandbox Code Playgroud)product: Main; prices: 145, 255; Expire: 10-Apr-2011; qty: 2; includes: Sub product: Sub; prices: 145, 255; Expire: 10-Apr-2011; qty: 2
然后将其解析为C#对象.这在单元测试中很容易使用(因为深层内部集合可以用单行编写),这在FitNesse类系统中使用更方便(因为这个DSL自然适合wiki),等等.
所以我使用它并编写解析器,但每次编写都很繁琐.我不是DSL /语言解析器的大专家,但我认为他们可以在这里提供帮助.什么是正确的使用?我只听说过:
但我甚至不知道选择哪一个以及从哪里开始.
所以问题是:使用某种DSL生成测试数据是否合理?你有什么建议吗?有现有案例吗?
更新:似乎我不够清楚.它不是关于原始字符串到对象转换.看第一行并将其与之相关联
var main = Product.New("Main")
.AddPrice(Price.New(145).WithType(PriceType.Main).AndQty(2))
.AddPrice(Price.New(255).WithType(PriceType.Maintenance).AndQty(2))
.Expiration(new DateTime(10, 04, 2011));
var sub = Product
.New("Sub").Parent(main)
.AddPrice(...));
main.AddSubProduct(sub);
products.Add(main);
products.Add(sub);
Run Code Online (Sandbox Code Playgroud)
请注意,我首先创建子产品,然后将其添加到main,即使它以相反的顺序列出.价格以特殊方式处理.我想指定Sub产品的名称并获得它的引用 - 创建.我想在单行上列出所有产品属性 - FLAT和NON-REPEATATIVE.我想使用属性的默认值.等等.
更新:我不相信避免使用DSL,因为所有替代示例都过于冗长且不便于用户使用.并且没有人说过有关DSL的任何有用的东西.
有人可以解释一下 Android 应用程序如何处理更新的技术细节吗?。应用程序通常需要发送什么类型的信息来请求更新,以及它会收到什么返回信息?。
首先,我正在使用Tomcat 5.5和我的.jsp在/webapps/foo/bar/*.jsp中.
我按照此处的说明设置了默认的404错误页面.在我输入的TOMCAT_HOME/conf/web.xml中:
<error-page>
<error-code>404</error-code>
<location>/error.html</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
我将测试error.html文件的副本丢弃到每个dirs中(我不确定/error.html指的是哪里):
/webapps/
/webapps/foo/
/webapps/foo/bar/
Run Code Online (Sandbox Code Playgroud)
每当我尝试在url的/foo/missingpage.html或/foo/bar/missingpage.html浏览器中访问不存在的页面时,我都会被重定向到/foo/error.html中存在的错误页面.
但是,尝试在url /missingpage.html的浏览器中访问不存在的页面会产生空白页.或者/missingDir/missingfile.html的任何排列也会产生一个空白页面.有什么建议?我错过了一些额外的配置吗?
谢谢
PR
当我加载gitk时,我得到一个关于参数的错误
Error in startup script: bad argument "zoomed": must be normal, iconic, or withdrawn
while executing
"wm state . $geometry(state)"
(procedure "makewindow" line 320)
invoked from within
"makewindow"
(file "/usr/local/git/bin/gitk" line 11250)
Run Code Online (Sandbox Code Playgroud)
有人知道解决方案吗?我正在使用Mac OS X 10.6.3
谢谢!