用Python方式纵向和横向汇总列表字典

时间:2019-03-10 17:51:50

标签: python dictionary

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Home Page"),
      ),
      body: FutureBuilder<HomePageStuffResponse>(
        future: getHomePageStuff(),
        builder: (context, snap) {
          if(snap.hasError) {
            return ErrorWidget('Error occurred while fetching data');
          }
          if(snap.hasData) {
            return Center(
             child: RaisedButton(
               onPressed: () {},
               child: Text('Go back!'),
             ),
          );
          }

        }
      ),
    );
  }
}


Future<HomePageStuffResponse> getHomePageStuff() async {
  Tokens token = await DBProvider.db.getToken();

  //Accessing the token here throws an NPE
  var accessToken = token.accessToken;
  debugPrint("token = " + accessToken);

  final response = await http.get(..);

  if (response.statusCode == 200) {
    debugPrint("FETCH SUCCESS");
    return stuff;
  } else {
    throw Exception('Failed to fetch home page stuff');
  }
}

我已经看到了对字典的每个列表求和的一种pythonic方法,但是有一种对字典中的列表的所有对应元素求和的pythonic方法吗?

dict = {1:[1,2,3,4],2:[5,5,5,3],3:[5,6,7,8]}

目前,我正在使用double for循环。

0 个答案:

没有答案