小编ale*_*mol的帖子

如何合并N个Python字典而不覆盖值?

我有以下词典列表:

list_of_ds = [
    {'a': [1, 2], 'b': [4, 5], 'c': [6, 7]},
    {'a': [4], 'b': [56], 'c': [46]},
    {'a': [92], 'b': [65], 'c': [43]}
]
Run Code Online (Sandbox Code Playgroud)

我希望这作为输出:

{'a': [1, 2, 4, 92], 'b': [4, 5, 56, 65], 'c': [6, 7, 46, 43]}
Run Code Online (Sandbox Code Playgroud)

到现在 ...

我试过了

d_of_ds = reduce(lambda d1, d2: d1.update(d2), list_of_ds)
Run Code Online (Sandbox Code Playgroud)

给出: AttributeError: 'NoneType' object has no attribute 'update'

我试过了

d_of_ds = reduce(lambda d1, d2: d1.update(d2) or d1, list_of_ds, {})
Run Code Online (Sandbox Code Playgroud)

覆盖每次迭代: {'a': [92], 'b': [65], 'c': [43]}

我试过了

d_of_ds …
Run Code Online (Sandbox Code Playgroud)

python merge dictionary

5
推荐指数
1
解决办法
182
查看次数

如何在 Bootstrap 面板内对齐同一行中的两个表?

我想将两个表格并排放置在同一个网格行中,但在运行以下代码时表格只会叠加:

<body>
...
<div class="container-fluid">
<div class="starter-template">

<div class='panel panel-primary'>
<div class='panel-heading'><h1>Main Title</h1></div>
<div class='panel-body'>

<div class='row-fluid'>
 <h4>Title</h4>
 <div class='span4'>
   <table class='table table-bordered'>
      <thead>
        <tr><th>feat1</th><th>feat2</th></tr></thead>
      <tbody>
      <tr><td>132</td><td>value a</td></tr>
      <tr><td>114</td><td>value b</td></tr>
      </tbody>
    </table>
  </div><!--closes table1-->

  <div class='span4'>
   <table class='table table-bordered'>
   <thead>
   <tr><th>feat1</th><th>feat3</th></tr>
      </thead>
      <tbody>
        <tr><td>264</td><td>val b</td></tr>
        <tr><td>3</td><td>val c</td></tr>
      </tbody>
    </table>
  </div><!--closes table2-->

</div>

</div><!--closes div panel-body-->
</div><!--closes div panel-->
</div> <!-- /.starter-template -->
</div><!-- /.container -->
...
</body>
Run Code Online (Sandbox Code Playgroud)

结果是所有行中的一个表,然后是第一个下方的第二个。

html css twitter-bootstrap

3
推荐指数
1
解决办法
7647
查看次数

标签 统计

css ×1

dictionary ×1

html ×1

merge ×1

python ×1

twitter-bootstrap ×1