使用python处理列表列表
我正在使用python编写列表 输入:使用python处理列表列表,python,list,Python,List,我正在使用python编写列表 输入: [[u'Tempoh', '', '', u'Belanjawan semasa', '', '', u'Perbelanjaan pembangunan', '', '', u'Lebihan / kurangan(-) keseluruhan', u'Sumber-sumber kewangan', '', '', '', '', '', ''], ['', '', '', u'Current budget', '', '', u'Developmen
[[u'Tempoh', '', '', u'Belanjawan semasa', '', '', u'Perbelanjaan pembangunan', '', '', u'Lebihan / kurangan(-) keseluruhan', u'Sumber-sumber kewangan', '', '', '', '', '', ''], ['', '', '', u'Current budget', '', '', u'Development expenditure', '', '', '', u'Sources of finance', '', '', '', '', '', ''], ['', '', '', u'Hasil', u'Perbelanjaan1', u'Lebihan / kurangan(-)', u'Perbelanjaan pembangunan kasar', u'Tolak: Terimaan balik pinjaman', u'Perbelanjaan pembangunan bersih', '', u'Pinjaman dalam negeri', '', '', u'Pinjaman luar negeri', '', '', u'Penggunaan harta2'], ['', '', '', '', '', '', '', '', '', '', u'Domestic borrowing', '', '', u'Foreign borrowing', '', '', ''], [u'Period', '', '', '', '', '', '', '', '', '', u'Peminjaman kasar dalam negeri', u'Tolak: Pembayaran balik dalam negeri', u'Peminjaman bersih dalam negeri', u'Peminjaman kasar luar negeri', u'Tolak: Pembayaran balik luar negeri', u'Peminjaman bersih luar negeri', ''], ['', '', '', u'Revenue', u'Expenditure1', u'Surplus / deficit(-)', u'Gross development expenditure', u'Less: Loan recoveries', u'Net development expenditure', u'Overall surplus / deficit(-)', u'Gross domestic borrowing', u'Less: Domestic repayment', u'Net domestic borrowing', u'Gross foreign borrowing', u'Less: Foreign repayment', u'Net foreign borrowing', u'Use of assets']
输出:
我希望此空白由上一个字符串填充
提前感谢您可以使用以下成语:
new = [s2 or s1 for s1, s2 in zip (stringList, stringList[1:])] # + last element
此列表包含一些嵌套列表,是否要将列表链接在一起,使其成为一个列表?还是只希望在嵌套列表中填充空格?当您说上一个字符串时,上一个字符串是否必须为非空?这在一些英语/马来语翻译中出现。但是我不明白你需要什么输出。你能举个例子吗?如果不是s2,那么s1的意思是什么?不管怎样,它都返回
s1
。这是一个打字错误,现已修复。我想您也可以使用以下代码执行此操作:s2或s1谢谢,每次我忘记此表单时。