import collections
data = [
{'firstname': 'John', 'lastname': 'Smith'},
{'firstname': 'Samantha', 'lastname': 'Smith'},
{'firstname': 'shawn', 'lastname': 'Spencer'},
]
new_data = collections.defaultdict(list)
for d in data:
new_data[d['lastname']].append(d['firstname'])
print new_data
Run Code Online (Sandbox Code Playgroud)
这是输出:
defaultdict(<type 'list'>, {'Smith': ['John', 'Samantha'], 'Spencer': ['shawn']})
Run Code Online (Sandbox Code Playgroud)
这是模板:
{% for lastname, firstname in data.items %}
<h1> {{ lastname }} </h1>
<p> {{ firstname|join:", " }} </p>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
但是我的模板中的循环不起作用.什么都没有出现.它甚至没有给我一个错误.我怎样才能解决这个问题?它应该显示姓氏和名字,如下所示:
<h1> Smith </h1>
<p> John, Samantha </p>
<h1> Spencer </h1>
<p> shawn </p>
Run Code Online (Sandbox Code Playgroud) 有没有人有使用NSURLRequest,NSURLConnection和NSURLRequestReturnCacheDataElseLoad策略实现图像缓存的示例代码?
我使用以下代码,但似乎没有发生缓存.我一直从URL获取图像.请告诉我这里有什么问题:
NSMutableURLRequest *req=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://i54.tinypic.com/10pd2jk.png"]];
NSData *data=[NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
NSLog(@"Received %d bytes", [data length]);
[req setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
data=[NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
NSLog(@"Received %d bytes", [data length]);
[[NSURLCache sharedURLCache] setMemoryCapacity:1024*1024*10];
UIImage *myImage = [UIImage imageWithData:data];
UIImageView *sd = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
sd.image = myImage;
[self.view addSubview:sd];
Run Code Online (Sandbox Code Playgroud) 我试图远程验证表单域.如果在我在页面上时该字段获得焦点,则一切都很有效.但是,如果该字段永远不会获得焦点,则表单需要我单击"提交"按钮两次才能成功提交.
我希望它只是验证字段是否获得焦点,或者以某种方式阻止表单需要两次单击才能提交.有人有主意吗?
$("#form1").validate({
rules: {
project: {
required: true,
remote: "check.php"
}
},
messages: {
project: {
required: "Required.",
remote: "Check Failed."
}
},
});
<input type="text" name="project" id="project" value="X"/>
Run Code Online (Sandbox Code Playgroud) 这似乎应该是非常容易的,但我很难搞清楚.
我想复制该<li>功能,使光盘图像显示在左侧,但应用于
标签
我有这个,但它没有显示光盘图像.
.list {
margin-top: 15px;
margin-bottom: 15px;
list-style:disc outside none;
display:inline;
}
<p class="list"><em>And Much, Much More!</em></p>
Run Code Online (Sandbox Code Playgroud)
我想尽可能避免使用任何图形来模拟子弹.
谢谢您的帮助
下面的代码失败了吗?可能是什么问题?
YouTubeRequestSettings settings = new YouTubeRequestSettings("whatwill come here ?",
"my api key",
"my youtube login email", "my youtube login password");
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "test 1";
newVideo.Tags.Add(new MediaCategory("Gaming", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "test 1 , test 2";
newVideo.Description = "test 3 test 4";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("tag 1, tag 2",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\test.avi", "video/quicktime");
Video createdVideo = request.Upload(newVideo);
Run Code Online (Sandbox Code Playgroud)
我解决了这个问题.这是我的类别:该类别必须是游戏而不是游戏.
我在使用Linux检查Java进程
top -H
Run Code Online (Sandbox Code Playgroud)
但是,我无法读取"COMMAND"列中的线程名称(因为它太长).如果我使用'c'来扩展进程的全名,那么它仍然很长.
如何获取命令的全名?
我正在使用Ruby的XML Builder并尝试找到正确的语法来重新创建以下RSS 2.0声明:
<rss version="2.0"
xmlns:g="http://base.google.com/ns/1.0">
Run Code Online (Sandbox Code Playgroud)
使用XML Builder将上述块放在一起的合适方法是什么?
如何对类GList进行部分特化,以便可以存储I的指针(即I*)?
template <class I>
struct TIList
{
typedef std::vector <I> Type;
};
template <class I>
class GList
{
private:
typename TIList <I>::Type objects;
};
Run Code Online (Sandbox Code Playgroud) 我看到一种奇怪的行为,我无法弄清楚.
我正在处理的网页有很多CSS样式.因此,对于我的一个div,我使用内联css根据我的要求制作宽度(在源代码中显示就好了).但是当我在Google Chrome中检查元素时,我发现计算出的宽度略小于我的值.我如何覆盖计算值.
谢谢
IIS 7.5在哪里记录错误?
事件查看器?日志文件?
我得到一个非常非特定的内部500错误.我想了解更多.
我运行PHP和我做了什么,这对本帖最后评论说.但仍然没有登录到C:\windows\temp.
css ×2
c# ×1
c++ ×1
cocoa ×1
django ×1
forms ×1
html ×1
html-lists ×1
iis-7.5 ×1
image ×1
iphone ×1
java ×1
jquery ×1
linux ×1
loops ×1
nsurlrequest ×1
php ×1
pointers ×1
python ×1
ruby ×1
templates ×1
top-command ×1
upload ×1
validation ×1
video ×1
xml-builder ×1
youtube ×1
youtube-api ×1