Skip to content

Instantly share code, notes, and snippets.

@k7faq
Created December 20, 2018 04:49
Show Gist options
  • Select an option

  • Save k7faq/d7ad631c0dc5c76eeb4023d3b0be3801 to your computer and use it in GitHub Desktop.

Select an option

Save k7faq/d7ad631c0dc5c76eeb4023d3b0be3801 to your computer and use it in GitHub Desktop.
# Mixed list of array(list) and integer
mixed=[ 'a', [1],2,[3], ['B'] ]
# function to extract value(s) from a list which may contain lists of integers
def flattenMixedList( mixed ):
for item in mixed:
if isinstance(item, list):
for thisItem in item: yield thisItem
else:
yield item
# call function to flatten list
print( list( flattenMixedList( mixed ) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment