0

I have this list object

[('migrations',), ('users',), ('devices',), ('externals',), ('cloud_securities',), ('operators',), ('promotions',), ('visitors',), ('caches',), ('captures',), ('mirror_settings',), ('wifis',), ('service_plans',), ('auto_provisionings',), ('guest_settings',), ('help_texts',), ('gateways',), ('fb_wifi_tokens',), ('health_check',), ('ubb_settings',), ('templates',), ('ubb_user_settings',), ('captive_portals',), ('languages',)]

I'm trying to make them as list of array

I tried

# table_names = np.asarray(table_names)

I got

[['migrations']
 ['users']
 ['devices']
 ['externals']
 ['cloud_securities']
 ['operators']
 ['promotions']
 ['visitors']
 ['caches']
 ['captures']
 ['mirror_settings']
 ['wifis']
 ['service_plans']
 ['auto_provisionings']
 ['guest_settings']
 ['help_texts']
 ['gateways']
 ['fb_wifi_tokens']
 ['health_check']
 ['ubb_settings']
 ['templates']
 ['ubb_user_settings']
 ['captive_portals']
 ['languages']]

But I want it like this

['migrations', 'users', 'devices', 'externals', 'cloud_securities', 'operators', 'promotions', 'visitors', 'caches', 'captures', 'mirror_settings', 'wifis', 'service_plans', 'auto_provisionings', 'guest_settings', 'help_texts', 'gateways', 'fb_wifi_tokens', 'health_check', 'ubb_settings', 'templates', 'ubb_user_settings', 'captive_portals', 'languages']

How can I do that python ?

What function should I use or look into ?

code-8
  • 54,650
  • 106
  • 352
  • 604

1 Answers1

5

you don't want numpy you want simple python & list comprehension:

Say l is your list, take each first & only item of the tuple element and rebuild a list from there:

newl = [x[0] for x in l]

A general solution if your tuples contained more than 1 element would involve itertools.chain to flatten the list but that's probably overkill here:

newl = list(itertools.chain.from_iterable(l))
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219