Getting Unique values from LISTS - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Getting Unique values from LISTS (/thread-21834.html) |
Getting Unique values from LISTS - aankrose - Oct-16-2019 #I wrote a program that come as a LIST output like below ['scext', '80.0'] ['scext', 'COLFUJDX440_DS11'] ['scext', 'Hard disk 1'] ['scext', '100.0'] ['scext', 'COLFUJDX440_DS11'] ['scext', 'Hard disk 2'] ['scext', '200.0'] ['scext', 'COLFUJDX440_DS11'] ['scext', 'Hard disk 3'] ['SCEXTVMD', '100.0'] ['SCEXTVMD', 'COLHG600P01_DS33'] ['SCEXTVMD', 'Hard disk 1'] ['SCEXTVMD', '40.0'] ['SCEXTVMD', 'COLHG600P01_DS33'] ['SCEXTVMD', 'Hard disk 2'] ['SCEXTVM', '100.0'] ['SCEXTVMD', 'COLHG600P01_DS33'] ['SCEXTVMD', 'Hard disk 3'] Please help me
RE: Getting Unique values from LISTS - metulburr - Oct-16-2019 This is not a single list, but numerous lists. So hence i grouped them together in a single list. lists = [ ['scext', '80.0'], ['scext', 'COLFUJDX440_DS11'], ['scext', 'Hard disk 1'], ['scext', '100.0'], ['scext', 'COLFUJDX440_DS11'], ['scext', 'Hard disk 2'], ['scext', '200.0'], ['scext', 'COLFUJDX440_DS11'], ['scext', 'Hard disk 3'], ['SCEXTVMD', '100.0'], ['SCEXTVMD', 'COLHG600P01_DS33'], ['SCEXTVMD', 'Hard disk 1'], ['SCEXTVMD', '40.0'], ['SCEXTVMD', 'COLHG600P01_DS33'], ['SCEXTVMD', 'Hard disk 2'], ['SCEXTVMD', '100.0'], ['SCEXTVMD', 'COLHG600P01_DS33'], ['SCEXTVMD', 'Hard disk 3'] ] d = {} for lst in lists: key = lst[0] value = lst[1] d.setdefault(key, []).append(value) print(d) or run it through pretty printer: The dictionary is close to the format you want, but has organized it near that format. You just have to print it out as you like.
RE: Getting Unique values from LISTS - aankrose - Oct-17-2019 import urllib3 from bs4 import BeautifulSoup import requests server_name="https:***********************************************" urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning http = urllib3.PoolManager() headers = urllib3.util.make_headers(basic_auth='****:****') r = http.request('GET', server_name, headers=headers) soup = BeautifulSoup(r.data, 'lxml') Server=[i.get_text() for i in soup.find_all('ops:name')] Identifier=[ i['identifier'] for i in soup.find_all('ops:resource') ] Convert_Dict_01 = dict(zip(Server,Identifier)) #print(Convert_Dict_01) for i in Identifier: Properties_URL="https:/*********/"+i+"/properties" r = http.request('GET', Properties_URL, headers=headers) soup=BeautifulSoup(r.data, 'lxml') Property_ID=[j['resourceid'] for j in soup.find_all('ops:resource-property') ] for element in soup.find_all("ops:property"): Name=element['name'] Total=[element.get_text()] if 'scsi' in Name: Convert_Dict_02 = dict(zip(Property_ID,Total)) for i,j in Convert_Dict_01.items(): for m,n in Convert_Dict_02.items(): if (Convert_Dict_01[i] == m): SERVER = [i] FINAL=[SERVER,Total] print(FINAL)
|