如何从数组中删除小于一定长度的字符串?

时间:2017-01-19 01:28:26

标签: python arrays string

所以,我正在关闭文本或网站,现在我正在寻找淘汰无用的内容并保留文章的内容。

这是我的数组的一部分:

[u'ADVERTISEMENT', u'\n            \n                By\n                \n\n\n                            \n                             Matthew Rocco\n                            \n                           \t\t\n\n\nPublished\n                January 18, 2017\n\nOil\n\n\n\n                            FOXBusiness\n\n', u'\n                    \n                    \n                    \n                        (Reuters)\n                    \n                ', u'Exxon Mobil (XOM) has joined a growing list of oil producers who are expanding in the Permian Basin of Texas, betting that America\u2019s shale boom is far from over.', u'Continue Reading Below', u'The world\u2019s largest publicly traded oil company inked a deal with the Bass family of Fort Worth, Texas, to double its footprint in the Permian. Exxon will pay up to $6.6 billion, mostly in stock, for approximately 275,000 acres of land. Exxon said 250,000 of those acres are located in the Permian, the largest oil field in America.', u'The acquisition is Exxon\u2019s most expensive move since its 2010 buyout of XTO Energy, which made Exxon the nation\u2019s top natural-gas producer. The deal is also Exxon\u2019s first under new CEO Darren Woods, who replaced Rex Tillerson after he was tapped as President-elect Donald Trump\u2019s nominee for Secretary of State.', u'\u201cThe deal doubles [Exxon\u2019s] estimated resources in place in the Permian, and sets the stage, in our view, for years of drillable inventory,\u201d CFRA Research analyst Stewart Glickman wrote in a note to clients.',...]

我想删除任何小于特定长度的项目。

1 个答案:

答案 0 :(得分:0)

使用带有条件的列表推导:

old_list =   ## your example
limit =      ## minimum length
new_list = [str for str in old_list if len(str) >= limit]