import json
myjson = """
{
"accounts": [
{
"alias": "string",
"balance": {
"amount": 0,
"currency": 0
},
"bankAlias": "string",
"currency": 0,
"defaultAccount": true,
"fsAlias": "string",
"hasBalance": true,
"title": "string",
"type": {
"id": "string",
"title": "string"
}
}
]
}
"""
data = json.loads(myjson)
print data["accounts"][0]["balance"]["amount"]
List<String> list = new ArrayList<>();
list.add("1");
list.add("2");
list.add("4");
list.add("1");
int summ = list.stream()
.map(s -> Integer.parseInt(s)) // перевод из String в int
.reduce( (s1,s2) -> s1 + s2 ) // сумма
.orElse(0); // значение по умолчанию
System.out.println(summ);
public class Reduce {
public static class Offer {
int price;
public Offer (int price) {
this.price = price;
}
public int getPrice() {
return price;
}
}
public static void main(String args[]) {
List< Offer > list = new ArrayList<>();
list.add(new Offer(1));
list.add(new Offer(2));
list.add(new Offer(4));
list.add(new Offer(1));
int summ = list.stream()
.map(Offer::getPrice) // взять прайс
.reduce( (s1,s2) -> s1 + s2 ) // сумма
.orElse(0); // значение по умолчанию
System.out.println(summ);
}
}
{% extends "layout.html" %}
{% block news %}
<div class="news--block">
{% for item in news %}
<div class="news--item">
<h1>{{ item.header }}</h1>
{{ item.body }}
</div>
{% endfor %}
</ul>
{% endblock %}
from flask import render_template
@app.route('/')
def hello(name=None):
news = [{"header":"Fake news: Trump died", "body":"Sorry, world."}, {"header":"Fake news: Trump now alive", "body":"Sorry, world again."}]
return render_template('main.html', news=news)