如何从二维列表中提取值列表

时间:2018-12-27 16:27:15

标签: python list arguments

如何从2d列表中提取满足某些条件的值列表?

如何清除空列表和多余的括号?

## application.yml
---
spring:
  profiles: dev
  datasource:
    platform: postgres
    url: 
jdbc:postgresql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
    username: ${DATABASE_USER}
    password: ${DATABASE_PASSWORD}
    driverClassName: org.postgresql.Driver
    initialize: true

  liquibase:
   change-log: classpath:db/changelog-master.xml

1 个答案:

答案 0 :(得分:0)

使用列表理解:

grid = [[10,13,17],[3,5,1],[13,1,12]]
results = [(i, b) for b in range(len(grid)) for i, a in enumerate(grid[b]) if a == 1]

输出:

[(2, 1), (1, 2)]