Saturday 15 May 2010

python - Comparison of two lists results in dictionary with duplacated items -


I am trying to work on comparing objects in two lists and {item_list1_as_key: item_list2_as_value} If the list is also a partial match of the wire, this function looks like this:

  Comparison of the latest inlists (referee, searchlist): matchdict = dict.fromkeys (referee, []) For items in context: for the Stitcum in the search list: If the item contains the Stitm: Print "key matches the% s string% s "Item" (item, statum) matchdict [item]. Append (return) match match referee = ["A", "b", "c"] searchlist = ["AAA", "BB though, Found:  
  key A mail string AAA key string matches a match with the key 'B' string item key B match string CBC key C match string CBC {'A': [ 'AAA', 'BB', 'BB', 'CBC', 'CBC', 'C': ['AAA', 'BB', 'BB', 'BB', 'CBC', 'CB Minister ']}  comparison that looks 

It worked well, but I can not go wrong with it .append function. Why do the search listings and duplicate items in non-matched items?

It appears that the line matchdict = dict.fromkeys (referee, []) < / Code> is using the context of the same list for each key as you have said, you can use a trick like this:

matchdict = {key: }}


No comments:

Post a Comment