Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract Unique value in nested lists

I have a list with different and repeated IP Addresses. So I want to extract a unique IP Address from the nested list.
enter image description here

import re
pattern='(\d+.{13,15})'
matches =[re.findall(pattern,str(x)) for x in dfs['Task Category']]
print(matches)  

import numpy as np 
new_list = list(np.concatenate(matches)) 
print(new_list)

[['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.178.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], [], [], [], [], [], ['192.168.101.115.'], ['192.168.101.178.'], [], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.82.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.79.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.79.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.79.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.43.'], ['192.168.101.62.'], [], ['192.168.101.62.'], [], ['192.168.101.62.'], ['192.168.101.115.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.43.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.82.'], ['192.168.101.91.'], [], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.115.'], ['192.168.101.115.'], ['192.168.101.178.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.82.'], ['192.168.101.91.'], ['192.168.101.82.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.82.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.82.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.62.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.115.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.62.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.91.'], ['192.168.101.252.'], ['192.168.101.252.'], ['192.168.101.252.'], ['192.168.101.252.'], ['192.168.101.252.'], ['192.168.101.252.']

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use a set or a Counter:

set(match for x in dfs['Task Category'] for match in re.findall(pattern,str(x))

Or:

from collections import Counter

Counter(match for x in dfs['Task Category'] for match in re.findall(pattern,str(x))

Or, using :

dfs['Task Category'].str.extractall(f'({pattern})')[0].unique()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading