Python : array tuple extraction -


results=[('uid=alex,class=zenth',{'age':['12'],'uidnumber':['12ac']}),('uid=beth,class=nenth',{'age':['22'],'uidnumber':['13sd']})] 

like have many tuples, how can extract uids want alex, beth , anyother uid in results array

i can

uid_val_list=[] _,val in enumerate(results):         list_vals=val[0].split(",")      uid_val=list_vals[0].split("=")[1]      uid_val_list.append(uid_val) 

is there better way it?

try:

import re  results = [('uid=alex,class=zenth', {'age': ['12'], 'uidnumber': ['12ac']}), ('uid=beth,class=nenth', {'age': ['22'], 'uidnumber': ['13sd']})]  c = re.compile('uid=(?p<uid>.+?),')  uid_val_list = [c.search(result[0]).group('uid') result in results] print(uid_val_list) 
  1. make compiled before search may speed up.
  2. except list comprehension, can use map() if like.

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -