From: fpinel at fedex.com (frederic pinel)
Date: Fri, 16 Apr 1999 05:48:49 +0200
Subject: Novice Question: two lists -> dictionary
References: <7f3j1v$f6j$1@nnrp1.dejanews.com>
Message-ID: <3716B321.A0652382@fedex.com>
Content-Length: 1249
X-UID: 1538                                                  

Here is a quick and dirty answer! Sorry...

ListA = ['10', '10', '20', '20', '20', '24']
ListB = ['23', '44', '11', '19', '57', '3']

ListT = []	# temporary list
Dict = {}

for i in range(len(ListA)):
	ListT = key_values(i, ListA, ListB)
	if (Dict.has_key(ListT[0]) == 0):
		Dict[ListT[0]] = ListT[1:]
		
print Dict	# print results, for test purposes. 


def key_values(i, l_key, l_val):
	" returns a list with the first item being the l_key[i] (ListA), 
	" and the values after for that key (ListB)
	resultat = []
	for j in range(len(l_key)):
		if (l_key[j] == l_key[i]):
			result[0] = l_key[i]
			result.append(l_val[j])
		
	return result

regards,
frederic

jwtozer at my-dejanews.com wrote:
> 
> How do I make the members of one list the key of a dictionary and the members
> of a second list the members of list values associated with with those keys?
> 
> Given:
> 
> ListA = ['10', '10', '20', '20', '20', '24']
> ListB = ['23', '44', '11', '19', '57', '3']
> 
> Desired Result:
> 
> Dict = {'10': ['23','44'],'20': ['11','19','57'], '24': ['3']}
> 
> Any help will be much appreciated.
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own




