'list comprehension remove 2d list (sublist) from list if length is less than 7 [closed]
How do I remove sublist from 2d list with list comprehension if string length is greater than 7? I only know how to do it in regular single dimension list.
Effort:
simple_list=['apple', 'banana', 'cantaloupe', 'durian']
mylist=[['apple'], ['banana'], ['cantaloupe'], ['durian']]
short_list = [blist for blist in simple_list if len (blist) <= 7]
Want:
short_list=[['apple'], ['banana'], ['durian']]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
