Skip to content

Instantly share code, notes, and snippets.

@imran-parray
Last active July 5, 2021 16:33
Show Gist options
  • Save imran-parray/4dc9f86ecd08aee6569e97a3c594eaea to your computer and use it in GitHub Desktop.
Save imran-parray/4dc9f86ecd08aee6569e97a3c594eaea to your computer and use it in GitHub Desktop.
data=['http://google.com?param1=value1',
'https://hello.com?param2=1&param3=3',
'https://hello.com?param1=1&param2=2&param4=4']
final_params=[]
all_prms=[]
for line in data:
all_prms.append(line.split('?')[1:][0].split('&'))
for line in all_prms:
for l in line:
final_params.append(l.split('=')[0])
unique_final=list(dict.fromkeys(final_params))
print(unique_final)
@imran-parray
Copy link
Author

# Shorter one
from urllib.parse import parse_qs, urlparse                                                                            
                                                                                                                      
data=['http://google.com?param1=value1',                                                                               
'https://hello.com?param2=1&param3=3',                                                                                 
'https://hello.com?param1=1&param2=2&param4=4']                                                                        
                                                                                                                      
print({param for url in data for param in parse_qs(urlparse(url).query)}

Amazing !!
Thanks alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment