Search Results

Search found 361 results on 15 pages for 'dictionaries'.

Page 1/15 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Combining entries, filtering of Python dictionaries

    - by matt
    I have two large lists that are filled with dictionaries. I need to combine the entries if a value from dict2==dict1 and place the newly combined matches somewhere else. I'm having trouble explaining it. List one contains: {'keyword':value, 'keyword2':value2} List two: {'keyword2':value2, 'keyword3':value3} I want a new list with dictionaries including keyword1, keyword2, and keyword3 if both lists share the same 'keyword2' value. What's the best way to do this? When I try, I only come up with tons of nested for loops. Thanks

    Read the article

  • Creating, using and managing XML component dictionaries quick tutorials

    - by drrwebber
    XML Component Dictionary capabilities are provided in conjunction with the CAM Editor toolset.  These dictionaries accelerate the development of consistent XML information exchanges using standard sets of dictionary components. The quick tutorials are aimed at showing the 'how to' of the basic capabilities to jump start use of XML dictionaries with the CAM Editor. The collection of dictionary tutorials videos run for a total of approximately 20 minutes.  Each video can be reviewed individually also. Learn how to use the dictionary functions to create dictionaries by harvesting data model components from existing XSD schema, SQL database table schema, or simple Excel / Open Office spreadsheets with tables of components listed.Also included are tips and functions relating to use of NIEM exchange development, IEPD and EIEM techniques.These videos should be viewed in conjunction with reviewing the overall concepts and techniques described in the companion video on the CAM Editor and Dictionaries overview.  The approach is aligned with OASIS and Core Components Technical Specification (CCTS) standards specifications for XML components and dictionaries.Dictionary collections can be stored locally on the file system, or local network, or collaboratively on the web or cloud deployment, or can be shared and managed securely using the Oracle Enterprise Repository (OER) tool. Also included are techniques relating to the use of the NIEM approach for developing XML exchange schema and IEPD packages.  This includes generating reuse scores, wantlist, and cross reference spreadsheets. Included in the latest release of the CAM Editor is the ability to use the analyse dictionary tool to determine duplicate components, conflicting component definitions, missing component descriptions and so on.  This ensures high quality dictionary component specifications.  Using the CAM Editor you can also create MindMap models and UML physical models of your dictionary components sets. For a complete guide to using the CAM Editor see the main YouTube video tutorials website and the CAM Editor website.

    Read the article

  • delete common dictionaries in list based on a value

    - by pythoonatic
    How would I delete all corresponding dictionaries in a list of dictionaries based on one of the dictionaries having a character in it. data = [ { 'x' : 'a', 'y' : '1' }, { 'x' : 'a', 'y' : '1/1' }, { 'x' : 'a', 'y' : '2' }, { 'x' : 'b', 'y' : '1' }, { 'x' : 'b', 'y' : '1' }, { 'x' : 'b', 'y' : '1' }, ] For example, how would I delete all of the x = a due to one of the y in the x=a having a / in it? Based on the example data above, here is where I would like to get to: cleaneddata = [ { 'x' : 'b', 'y' : '1' }, { 'x' : 'b', 'y' : '1' }, { 'x' : 'b', 'y' : '1' }, ]

    Read the article

  • How do I add missing dictionaries for aspell?

    - by Ahmed
    Aspell version: $ aspell -v @(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6) Dump dict yields no results: $ aspell dump dicts First noticed the problem when I did this, was originally working on web server, but someone updated something and it hasn't worked since: $ aspell check temp_test_file.txt Error: No word lists can be found for the language "en_US". What's the proper way of installing the required dictionaries? I believe we're running this on CentOS. And also, /usr/lib/aspell-0.60 does not contain the required dictionaries (provided that they're supposed to be saved there). data-dir: /usr/lib/aspell-0.60

    Read the article

  • Merging dictionaries in C#

    - by orip
    What's the best way to merge 2 or more dictionaries (Dictionary<T1,T2>) in C#? (3.0 features like LINQ are fine). I'm thinking of a method signature along the lines of: public static Dictionary<TKey,TValue> Merge<TKey,TValue>(Dictionary<TKey,TValue>[] dictionaries); or public static Dictionary<TKey,TValue> Merge<TKey,TValue>(IEnumerable<Dictionary<TKey,TValue>> dictionaries); EDIT: Got a cool solution from JaredPar and Jon Skeet, but I was thinking of something that handles duplicate keys. In case of collision, it doesn't matter which value is saved to the dict as long as it's consistent.

    Read the article

  • Any way to make DataContractJsonSerializer serialize Dictionaries properly?

    - by morpheus
    The DataContractJsonSerializer is not able to serialize Dictionaries properly. Whereas JavaScriptSerializer serializes Dictionaries as {"abc":"xyz","def":42} for example, the DataContractJsonSerializer gives [{"Key":"abc","Value":"xyz"},{"Key":"def","Value":42}] instead. This is really problematic and I want to know how can I serialize Dictionary objects correctly in my WCF service. I am looking for a solution that would require least amount of effort. ref: http://msdn.microsoft.com/en-us/library/bb412170.aspx

    Read the article

  • Trouble with copying dictionaries and using deepcopy on an SQLAlchemy ORM object

    - by Az
    Hi there, I'm doing a Simulated Annealing algorithm to optimise a given allocation of students and projects. This is language-agnostic pseudocode from Wikipedia: s ? s0; e ? E(s) // Initial state, energy. sbest ? s; ebest ? e // Initial "best" solution k ? 0 // Energy evaluation count. while k < kmax and e > emax // While time left & not good enough: snew ? neighbour(s) // Pick some neighbour. enew ? E(snew) // Compute its energy. if enew < ebest then // Is this a new best? sbest ? snew; ebest ? enew // Save 'new neighbour' to 'best found'. if P(e, enew, temp(k/kmax)) > random() then // Should we move to it? s ? snew; e ? enew // Yes, change state. k ? k + 1 // One more evaluation done return sbest // Return the best solution found. The following is an adaptation of the technique. My supervisor said the idea is fine in theory. First I pick up some allocation (i.e. an entire dictionary of students and their allocated projects, including the ranks for the projects) from entire set of randomised allocations, copy it and pass it to my function. Let's call this allocation aOld (it is a dictionary). aOld has a weight related to it called wOld. The weighting is described below. The function does the following: Let this allocation, aOld be the best_node From all the students, pick a random number of students and stick in a list Strip (DEALLOCATE) them of their projects ++ reflect the changes for projects (allocated parameter is now False) and lecturers (free up slots if one or more of their projects are no longer allocated) Randomise that list Try assigning (REALLOCATE) everyone in that list projects again Calculate the weight (add up ranks, rank 1 = 1, rank 2 = 2... and no project rank = 101) For this new allocation aNew, if the weight wNew is smaller than the allocation weight wOld I picked up at the beginning, then this is the best_node (as defined by the Simulated Annealing algorithm above). Apply the algorithm to aNew and continue. If wOld < wNew, then apply the algorithm to aOld again and continue. The allocations/data-points are expressed as "nodes" such that a node = (weight, allocation_dict, projects_dict, lecturers_dict) Right now, I can only perform this algorithm once, but I'll need to try for a number N (denoted by kmax in the Wikipedia snippet) and make sure I always have with me, the previous node and the best_node. So that I don't modify my original dictionaries (which I might want to reset to), I've done a shallow copy of the dictionaries. From what I've read in the docs, it seems that it only copies the references and since my dictionaries contain objects, changing the copied dictionary ends up changing the objects anyway. So I tried to use copy.deepcopy().These dictionaries refer to objects that have been mapped with SQLA. Questions: I've been given some solutions to the problems faced but due to my über green-ness with using Python, they all sound rather cryptic to me. Deepcopy isn't playing nicely with SQLA. I've been told thatdeepcopy on ORM objects probably has issues that prevent it from working as you'd expect. Apparently I'd be better off "building copy constructors, i.e. def copy(self): return FooBar(....)." Can someone please explain what that means? I checked and found out that deepcopy has issues because SQLAlchemy places extra information on your objects, i.e. an _sa_instance_state attribute, that I wouldn't want in the copy but is necessary for the object to have. I've been told: "There are ways to manually blow away the old _sa_instance_state and put a new one on the object, but the most straightforward is to make a new object with __init__() and set up the attributes that are significant, instead of doing a full deep copy." What exactly does that mean? Do I create a new, unmapped class similar to the old, mapped one? An alternate solution is that I'd have to "implement __deepcopy__() on your objects and ensure that a new _sa_instance_state is set up, there are functions in sqlalchemy.orm.attributes which can help with that." Once again this is beyond me so could someone kindly explain what it means? A more general question: given the above information are there any suggestions on how I can maintain the information/state for the best_node (which must always persist through my while loop) and the previous_node, if my actual objects (referenced by the dictionaries, therefore the nodes) are changing due to the deallocation/reallocation taking place? That is, without using copy?

    Read the article

  • Dictionaries with more than one key per value in Python

    - by nickname
    I am attempting to create a nice interface to access a data set where each value has several possible keys. For example, suppose that I have both a number and a name for each value in the data set. I want to be able to access each value using either the number OR the name. I have considered several possible implementations: Using two separate dictionaries, one for the data values organized by number, and one for the data values organized by name. Simply assigning two keys to the same value in a dictionary. Creating dictionaries mapping each name to the corresponding number, and vice versa Attempting to create a hash function that maps each name to a number, etc. (related to the above) Creating an object to encapsulate all three pieces of data, then using one key to map dictionary keys to the objects and simply searching the dictionary to map the other key to the object. None of these seem ideal. The first seems ugly and unmaintainable. The second also seems fragile. The third/fourth seem plausible, but seem to require either much manual specification or an overly complex implementation. Finally, the fifth loses constant-time performance for one of the lookups. In C/C++, I believe that I would use pointers to reference the same piece of data from different keys. I know that the problem is rather similar to a database lookup problem by a non-key column, however, I would like (if possible), to maintain the approximate O(1) performance of Python dictionaries. What is the most Pythonic way to achieve this data structure?

    Read the article

  • Python: Check if all dictionaries in list are empty

    - by Brant
    I have a list of dictionaries. I need to check if all the dictionaries in that list are empty. I am looking for a simple statement that will do it in one line. Is there a single line way to do the following (not including the print)? l = [{},{},{}] # this list is generated elsewhere... all_empty = True for i in l: if i: all_empty = False print all_empty Somewhat new to python... I don't know if there is a shorthand built-in way to check this. Thanks in advance.

    Read the article

  • Merging similar dictionaries in a list together

    - by WonderSteve
    New to python here. I've been pulling my hair for hours and still can't figure this out. I have a list of dictionaries: [ {'FX0XST001.MID5': '195', 'Name': 'Firmicutes', 'Taxonomy ID': '1239', 'Type': 'phylum'} {'FX0XST001.MID13': '4929', 'Name': 'Firmicutes', 'Taxonomy ID': '1239','Type': 'phylum'}, {'FX0XST001.MID6': '826', 'Name': 'Firmicutes', 'Taxonomy ID': '1239', 'Type': 'phylum'}, . . . . {'FX0XST001.MID6': '125', 'Name': 'Acidobacteria', 'Taxonomy ID': '57723', 'Type': 'phylum'} {'FX0XST001.MID25': '70', 'Name': 'Acidobacteria', 'Taxonomy ID': '57723', 'Type': 'phylum'} {'FX0XST001.MID40': '40', 'Name': 'Acidobacteria', 'Taxonomy ID': '57723', 'Type': 'phylum'} ] I want to merge the dictionaries in the list based on their Type, Name, and Taxonomy ID [ {'FX0XST001.MID5': '195', 'FX0XST001.MID13': '4929', 'FX0XST001.MID6': '826', 'Name': 'Firmicutes', 'Taxonomy ID': '1239', 'Type': 'phylum'} . . . . {'FX0XST001.MID6': '125', 'FX0XST001.MID25': '70', 'FX0XST001.MID40': '40', 'Name': 'Acidobacteria', 'Taxonomy ID': '57723', 'Type': 'phylum'}] I have the data structure setup like this because I need to write the data to CSV using csv.DictWriter later. Would anyone kindly point me to the right direction?

    Read the article

  • Performance comparison of Dictionaries

    - by Hun1Ahpu
    I'm interested in performance values (big-O analysis) of Lookup and Insert operation for .Net Dictionaries: HashTable, SortedList, StringDictionary, ListDictionary, HybridDictionary, NameValueCollection Link to a web page with the answer works for me too.

    Read the article

  • C# Array of Dictionaries

    - by Nave
    I want to create an array of Dictionaries. But the array size is unknown. For integer, i used List to obtain the integer array of unknown size. But in the case of Dictionary, am not able to create a list of Dictionary. Is thr any wayz by which this can be done? Dictionary(int, String) paramList=null;I am want to create the array of paramList(above). I am using C Sharp.

    Read the article

  • Free or open source dictionaries

    - by jack
    I'm working on a multi-lingual search engine. I need to map keywords in English to corresponding words in following languages: Bulgarian Catalan Chinese Crotian Czech Danish Dutch Finish French German Greek Hungarian Italian Japanese Korean Lithuanian Litvian Norwegian Polish Portuguese Romanian Russian Slovak Slovenian Spanish Swedish Thai Ukrainian Vietnamese I already known eudict and stardict. Could you recommend some other free or open source dictionaries cover one or more above languages?

    Read the article

  • More nest Python nested dictionaries.

    - by clutch
    After reading http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python why is it wrong to do: c = collections.defaultdict(collections.defaultdict(int)) in python? I would think this would work to produce {key:{key:1}} or am I thinking about it wrong?

    Read the article

  • constructorless initialization and Dictionaries

    - by Stacey
    Using C# 3.0, we can initialize objects without their constructors for syntactical reasons. Such as .. ClassName c = new ClassName = { Property1 = "Value" } I was wondering how this works with Dictionaries and adding the items to them. Any ideas? class Foo { public Dictionary DictionaryObject { get; set; } } Foo f = new Foo = { // ??? } Thank you for your time!!

    Read the article

  • Python Naming Conventions for Dictionaries/Maps/Hashes

    - by pokstad
    While other questions have tackled the broader category of sequences and modules, I ask this very specific question: "What naming convention do you use for dictionaries and why?" Some naming convention samples I have been considering: # 'value' is the data type stored in the map, while 'key' is the type of key value_for_key={key1:value1, key2,value2} value_key={key1:value1, key2,value2} v_value_k_key={key1:value1, key2,value2} Don't bother answering the 'why' with "because my work tells me to", not very helpful. The reason driving the choice is more important. Are there any other good considerations for a dictionary naming convention aside from readability?

    Read the article

  • dictionary of lists of dictionaries in python

    - by Andy
    I'm a perl scripter working in python and need to know a way to do the following perl in python. $Hash{$key1}[$index_value]{$key2} = $value; I have seen the stackoverflow question here: List of dictionaries, in a dictionary - in Python I still don't understand what self.rules is doing or if it works for my solution. My data will be coming from files, and will I will be using regexes to capture to temporary variables until ready to store in the data structure. If you need to ask, the order related to the $index_value is important and would like to be maintained as an integer. Any suggestions are appreciated or if you think I need to rethink data structures with Python that would be helpful.

    Read the article

  • Parsing a list of dictionaries passed as a POST parameter

    - by andyashton
    I have a list of python dictionaries that look like this: sandwiches = [ {'bread':'wheat', 'topping':'tomatoes', 'meat':'bacon'}, {'bread':'white', 'topping':'peanut butter', 'meat':'bacon'}, {'bread':'sourdough', 'topping':'cheese', 'meat':'bacon'} ] I want to pass this as a POST parameter to another Django app. What does the client app need to do to iterate through the list? I want to do something like: for sandwich in request.POST['sandwiches']: print "%s on %s with %s is yummy!" % (sandwich['meat'], sandwich['bread'], sandwich['topping']) But I don't seem to have a list of dicts when my data arrives at my client app.

    Read the article

  • Selecting a value from multiple dictionaries inside an enumeration

    - by johaanfaust
    If I have an enumeration of dictionaries IEnumerable<IDictionary<string, float>> enumeration can I perform a Linq query on it so that I can select by a value from each dictionary in the enumeration using the same key? I can do this in a loop: float f; foreach (var dictionary in enumeration) { if (dictionary.TryGetValue("some key", out f)) { Console.WriteLine(f); } } (The eventual plan is to compare the performance of the query verses the equivalent nested looping statements (the enumeration itself is formed from either another query or an equivalent set of loops).)

    Read the article

  • Deserializing a complex JSON result (array of dictionaries) with TouchJSON

    - by jpm
    I did a few tests with TouchJSON last night and it worked pretty well in general for simple cases. I'm using the following code to read some JSON content from a file, and deserialize it: NSString *jsonString = [[NSString alloc] initWithContentsOfFile:@"data.json"]; NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding]; NSError *error = nil; NSDictionary *items = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; NSLog(@"total items: %d", [items count]); NSLog(@"error: %@", [error localizedDescription]); That works fine if I have a very simple JSON object in the file (i.e. a dictionary): {"id": "54354", "name": "boohoo"} This way I was able to get access to the array of values, as I wanted to get the item based on its index within the list: NSArray *items_list = [items allValues]; NSString *name = [items_list objectAtIndex:1]; (I understand that I could have fetched the name with the dictionary API) Now I would like to deserialize a semi-complex JSON string, which represents an array of dictionaries. An example of such a JSON string is below: [{"id": "123456", "name": "touchjson"}, {"id": "3456", "name": "bleh"}] When I try to run the same code above against this new content in the data.json file, I don't get any results back. My NSLog() call says "total items: 0", and no error is coming back in the NSError object. Any clues on what is going on? I'm completely lost on what to do, as there isn't much documentation available for TouchJSON, and much less usage examples.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >