pyTony i learned lots from this code you used in resoponce to thread

i first mixed up the input and was supprised at the result which only printed last occurence of the key in the dictionary list...

i did work out how to sort it first and reproduce your results.

changed the input to

man1 car
man2 jacket
man2 house
man1 wallet
man1 shirt
man1 car
man2 truck
man2 jacjet
man2 computer
man1 car
man1 shirt
man2 jacket

then added a steps to sort it and output was exactly as yours ... thanks again great work...

# pair up data
data = [d.split() for d in rawdata if d]
# group common data without sorting 
data = [(key, [b for a,b in g]) for key, g in groupby(data, itemgetter(0))]
# sort data 

i am missing some basic language idea and not seeing why the original you made did not take my input and create these results

{'man1': {'car': 1}, 'man2': {'jacket': 1,'house': 1},'man1': {'wallet': 1,'car': 1, 'shirt': 1}, 'man2': {'truck': 1,'jacket': 1,'computer': 1},'man1': {'car': 1, 'shirt': 1}, 'man2': {'jacket': 1}}

what should be added to your code to get this result ... thanks in advance for all the help breaking down this language into valuable tools ..

BTW i think i get how the dictionary idea is a lambda or lisp style code and will hope to explore the idea of creating some AI similar to my lisp days ... o the canoe problem and Lisa program ....

Recommended Answers

All 2 Replies

Groupby needs sorted input, yours is not.

thanks still working on what OOP code others used

helps but i will need to look harder to see what code i can replace groupby to produce the result that i think the original thread was trying to produce ... ...

a new way of thinking is always a slow proccess

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.