for i in names:
dict[i] = {'firstname': name[i]['firstname'],
'lastname': name[i]['lastname']}
print dict[0]['firstname'] # John
print dict[0]['lastname'] # Doe
# group similar lastnames, along with their firstnames
# ...
return render_to_response('index.html', dict)
同様の姓で終わる名前をグループ化する必要があります。 たとえば、出力は次のようになります。Python dict質問です。類似の文字列をグループ化するには?
<html>
<body>
<h1> Doe </h1>
<p> John, Jason, Peter </p>
<h1> Avery </h1>
<p> Kelly, Brittany </p>
</body>
</html>
「H1」のタグが最後の名前が含まれていることになってと「p」は最初の名前をタグです。
どうすればよいですか?
"類似して"あなたは実際に "等しい"を意味しますか? –
はい、それは私が意味するものです。 – user216171