Augment elements of a list Programming Software Development by rahul8590 I have various list being generated by a mapper function in this format >>> mapper("b.txt" , i["b.txt"]) [('thats', 1), ('one', 1), ('small', 1), ('step', 1), ('for', 1), ('a', 1), ('man', 1), ('one', 1), ('giant', 1), ('leap', 1), ('for', 1), ('mankind', 1)] >>> mapper("c.txt" , i["… Re: Augment elements of a list Programming Software Development by woooee Personal preference here is to use a dictionary, with the key being the word, pointing to the number. Convert the first list to a dictionary, loop through the second list and if the word is found in the dictionary, add to the number [url]http://www.greenteapress.com/thinkpython/html/book012.html#toc120[/url] Post back with any code you are having… Re: Augment elements of a list Programming Software Development by Beat_Slayer It can be just me, but it seems something is wrong! Can you explain a little further. You want to know the words that exist in the two files, is that it? Or do you want to count the ocurrences in each file? Re: Augment elements of a list Programming Software Development by rahul8590 @Beat_slayer well .. the complete picture is i am implementing MapReduce framework .. i didnt find ne ( in python ) for me so decided to code by myself , i have come as far as writting mapper function and got stuck up in this list to dictionary conversion .. For simplicity purpose i have mentioned 2 files here .. the actual thing will have more… Re: Augment elements of a list Programming Software Development by rahul8590 @woooee: the 1st part i have coded ,and converted the list to dictionaries [CODE] >>> l [('a', 0), ('c', 2), ('b', 1), ('e', 4), ('d', 3)] >>> dd= {} >>> i = 0 >>> while i < len(l): ... s = l[i] ... dd[s[0]] = s[1] ... i = i + 1 ... >>> dd {'a': 0, 'c': 2, 'b': 1, 'e': 4, 'd': 3} [/CODE] now … Re: Augment elements of a list Programming Software Development by Beat_Slayer I think this should give some insight, if I'm understanding what you are trying to do. [CODE]def merge_dic(merged_dic, wordlist): for item in wordlist: if merged_dic.has_key(item): merged_dic[item] += 1 else: merged_dic[item] = 1 file1 = 'this is a dummy sample file for example as sample' … Re: Augment elements of a list Programming Software Development by TrustyTony [CODE]## Your way l = [('a', 0), ('c', 2), ('b', 1), ('e', 4), ('d', 3)] dd= {} i = 0 while i < len(l): s = l[i] dd[s[0]] = s[1] i = i + 1 print dd #{'a': 0, 'c': 2, 'b': 1, 'e': 4, 'd': 3} ## shorter way dd=dict(l) print dd """Output: {'a': 0, 'c': 2, 'b': 1, 'e': 4, 'd': 3} {'a': 0, 'c': 2, 'b': 1, 'e': … Re: Augment elements of a list Programming Software Development by woooee Use a function and pass the file name to it. Some pseudo-code: [CODE]def mapper_dict(fname, word_dict): ## assumes word is first element after split() fp = open(fname, "r") for rec in fp: substrs = rec.split() word = substrs[0] if word not in word_dict: word_dict[word] = 0 … Re: Augment elements of a list Programming Software Development by rahul8590 @tonyjv: Both of our codes have a bug...... unquestionably ur method is the shortest ... i felt like a moron when i saw that conversions implicitly existed , but foe example [CODE] >>> l1 [('the', 1), ('quick', 1), ('brown', 1), ('fox', 1), ('jumped', 1), ('over', 1), ('the', 1), ('lazy', 1), ('grey', 1), ('dogs', 1)] >>> d1 = … Re: Augment elements of a list Programming Software Development by woooee This should be: [CODE] ## changed to s[0] and d1, di.keys() is not necessary if s[0] not in d1: [/CODE] Re: Augment elements of a list Programming Software Development by rahul8590 [CODE] >>> while i < len(l1): ... s = l1[i] ... if s[0] not in d1: ... d1[s[0]] = s[1] ... else: ... d1[s[0]] += 1 ... i = i + 1 ... >>> d1 {} [/CODE] geting empty dictionary .. :( Re: Augment elements of a list Programming Software Development by Beat_Slayer How about this? [CODE]class Word_Counter(): def __init__(self): self.count = {} def add_string(self, s): word_list = s.split(' ') self.add_list(word_list) def add_list(self, wl): for item in wl: if self.count.has_key(item): self.count[item] += 1 … Re: Augment elements of a list Programming Software Development by TrustyTony [QUOTE=rahul8590;1296664][CODE] >>> while i < len(l1): ... s = l1[i] ... if s[0] not in d1: ... d1[s[0]] = s[1] ... else: ... d1[s[0]] += 1 ... i = i + 1 ... >>> d1 {} [/CODE] geting empty dictionary .. :([/QUOTE] [CODE]words=[('the', 1), ('quick', 1), ('brown', 1), ('fox', 1), ('jumped', 1), ('… Re: Augment elements of a list Programming Software Development by ultimatebuster using dictionary it's very simple For example: I have a list like this: ["thing1", "thing2", "thing3", "thing4", "thing1"] If i understood you correctly, you want thing1 to have a 2 associated with it. This code would do it: [CODE] li = ["thing1", "thing2", "thing3… A problem Programming Software Development by KAY111 … v->match(u); u->match(v); break; } } } } void augment(Ynode *last) { Ynode *v, *v1; Xnode *w; arc *e; v…); S.enqueue(w); } else { foundPath = true; v->setCurrent(u); augment(v); break; } } } while (!foundPath && !Q.isEmpty()); // get ready… expected primary-expression before 'for' Programming Software Development by KAY111 …;match(v); break; } } } } void augment(Ynode *last) { Ynode *v, *v1; Xnode…else { foundPath = true; v->setCurrent(u); augment(v); break; } } } while (!foundPath &&… Rational Programming Software Development by ahmedhesham 1. Rational Implement a rational number class: Rational Augment your class with methods for: a) Initialization (Constructor): parameters are … number All your numbers should be saved in Reduced Form Augment your code with a driver class (that contains "main… Augmented Reality for Small Unmanned Aerial Systems Programming Software Development by tumblinmonkeym … Small Unmanned Aerial Systems at CBRN Events This project will augment video imagery from a small UAS with labels showing responders… the robot is looking. This project applies visualization principles to augment the image with information extracted from Google maps. The project… Sentiment Analysis with Data Augmentation Using ChatGPT Programming Computer Science by usmanmalik57 … techniques, such as data augmentation, to generate synthetic data and augment the training set. In this article, we will delve into… of 0.6916. ## Data Augmentation with ChatGPT ## Let’s now augment our data using ChatGPT. We will generate 100 more reviews… Need help with string manipulation and seg faults Programming Software Development by Marauder_Pilot … the list from that number, replace it with a word, augment the list accordingly and continue. Anyways, here's what I… script to email new ip Programming Software Development by 6figganigga … if some of you guru's may be able to augment this script to ONLY email me when the external IP… I need the helps, the deadline is coming soon... Programming Software Development by vincent551987vn … define all methods specified in the class VeryLongInt. You can augment some your own methods into this class but you are… New CWS trojan - GoogleSpawner - uses Firefox extension to hijack Firefox Hardware and Software Information Security by InetVirusGuard … that it is attempting simulate clickthrus from different users, to augment google search placement and to generate revenue directly from sites… LNK2001 and LNK2019 problem! Programming Software Development by padawan … = Order[m]; /* Node's index */ if (!growlist(knode)) return(101); /* Augment adjacency list */ Order[m] = Order[k]; /* Switch order of nodes… cyclic codes help Programming Software Development by AutoC … division perform the following: Load the register with zero bits. Augment the message by appending W zero bits to the end… Interaction Dialer Digital Media Digital Marketing by marsgivson … matter your business, a well-planned, well-executed campaign can augment nearly any marketing and relationship management process and build revenues… China Rising: Go East for Good Tech Plays Community Center by Brian.oco … came about after reports suggested that the Chinese government may augment its previously announced stimulus package.” Additionally, says Trading Markets, an… This is Steve to Daniweb Community Center Say Hello! by stevelg … writing Java based cloud applications. I joined Daniweb to help augment my skills in Java. I have written a number of… Now Zeus 2 botnet adds client side cookie harvesting Hardware and Software Information Security by happygeek … extra information on the user that can be used to augment their illegal access to those users' online accounts. Coupled with… cryptography technique Programming Software Development by jecris … Qs in a row, insert a Z between them. Also, augment oddlength messages ending with a Q by using a Z…