Reputation: 2249
I have the following tuple
TOPICS = (
(_('Politics and Government'), (
(1, _('(1) Women politicians, women electoral candidates...')),
(2, _('(2) Peace, negotiations, treaties...(local, regional, national),')),
(3, _('(3) Other domestic politics/government (local, regional, national), elections, speeches, the political process ...')),
(4, _('(4) Global partnerships (international trade and finance systems, e.g. WTO, IMF, World Bank, debt) ...')),
(5, _('(5) Foreign/international politics, relations with other countries, negotiations, treaties, UN peacekeeping ...')),
(6, _('(6) National defence, military spending, military training, military parades, internal security ...')),
(7, _('(7) Other stories on politics and government (specify the topic in \'Comments\' section of coding sheet)')),
)
),
(_('Economy'), (
(8, _('(8) Economic policies, strategies, modules, indicators, stock markets, taxes,...')),
(9, _('(9) Economic crisis, state bailouts of companies, company takeovers and mergers ...')),
(10, _('(10) Poverty, housing, social welfare, aid to those in need ...')),
(11, _('(11) Women’s participation in economic processes (informal work, paid employment, unemployment, unpaid labour)')),
(12, _('(12) Employment')),
(13, _('(13) Informal work, street vending, ...')),
(14, _('(14) Other labour issues, strikes, trade unions, negotiations, other employment and unemployment')),
(15, _('(15) Rural economy, agriculture, farming practices, agricultural policy, land rights ...')),
(16, _('(16) Consumer issues, consumer protection, regulation, prices, consumer fraud ...')),
(17, _('(17) Transport, traffic, roads...')),
(18, _('(18) Other stories on the economy (specify the topic in \'Comments\' section of coding sheet)')),
)
),
)
and I want to flatten it to get a list of the inner tuples only something like
[(1, _('(1) Women politicians, women electoral candidates...')),
(2, _('(2) Peace, negotiations, treaties...(local, regional, national),')),
(18, _('(18) Other stories on the economy (specify the topic in \'Comments\' section of coding sheet)'))]
any tips on how I can write a list comprehension for this?
Upvotes: 0
Views: 56
Reputation: 3722
This works:
[y for x in TOPICS for y in x[1]]
Output:
[(1, '(1) Women politicians, women electoral candidates...'),
(2, '(2) Peace, negotiations, treaties...(local, regional, national),'),
(3,
'(3) Other domestic politics/government (local, regional, national), elections, speeches, the political process ...'),
(4,
'(4) Global partnerships (international trade and finance systems, e.g. WTO, IMF, World Bank, debt) ...'),
(5,
'(5) Foreign/international politics, relations with other countries, negotiations, treaties, UN peacekeeping ...'),
(6,
'(6) National defence, military spending, military training, military parades, internal security ...'),
(7,
"(7) Other stories on politics and government (specify the topic in 'Comments' section of coding sheet)"),
(8,
'(8) Economic policies, strategies, modules, indicators, stock markets, taxes,...'),
(9,
'(9) Economic crisis, state bailouts of companies, company takeovers and mergers ...'),
(10, '(10) Poverty, housing, social welfare, aid to those in need ...'),
(11,
'(11) Women’s participation in economic processes (informal work, paid employment, unemployment, unpaid labour)'),
(12, '(12) Employment'),
(13, '(13) Informal work, street vending, ...'),
(14,
'(14) Other labour issues, strikes, trade unions, negotiations, other employment and unemployment'),
(15,
'(15) Rural economy, agriculture, farming practices, agricultural policy, land rights ...'),
(16,
'(16) Consumer issues, consumer protection, regulation, prices, consumer fraud ...'),
(17, '(17) Transport, traffic, roads...'),
(18,
"(18) Other stories on the economy (specify the topic in 'Comments' section of coding sheet)")]
Upvotes: 1