Search Results

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

Page 10/15 | < Previous Page | 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Using VirtualMode on a DataGridView when the number of rows/columns isn't known

    - by Nathan Baulch
    I need to display an unknown length sequence of dictionaries with unknown keys efficiently in a data grid. This sequence is the result of a potentially slow LINQ query that could contain any number of results. At first I thought that VirtualMode on DataGridView was what I was looking for but it appears that the number of rows and columns must be known upfront. I tried adding a single row and column then adding more as needed from the CellValueNeeded event but this doesn't work. Is this even possible with VirtualMode? Or do I need to estimate how many rows are visible on the screen and manually build up the rows/columns? And if so, how do I ensure that a vertical scrollbar is present and react appropriately when a user uses it?

    Read the article

  • advanced python autovivification

    - by Zhang18
    This question is about implementing the full PERL autovivification in python. I know similary questions were asked before and so far the best answre is http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python/652284#652284. However, I'm looking to do this: a['x']['y'].append('z') without declaring a['x']['y'] = [] first, or rather, not declaring a['x'] = {} either. I know dict and list classes sorta don't mix so this is hard, but I'm interested in seeing if someone has an ingenius solution probably involving creating an inherited class from dict but defined a new append method on it? I also know this might throw off some python purists who will ask me to stick with Perl. But even just for a challenge, I'd like to see something. thx!

    Read the article

  • How to implement arrays in an interpreter?

    - by Ray
    I have managed to write several interpreters including Tokenizing Parsing, including more complicated expressions such as ((x+y)*z)/2 Building bytecode from syntax trees Actual bytecode execution What I didn't manage: Implementation of dictionaries/lists/arrays. I always got stuck with getting multiple values into one variable. My value structure (used for all values passed around, including variables) looks like this, for example: class Value { public: ValueType type; int integerValue; string stringValue; } Works fine with integers and strings, but how could I implement arrays? (From now on with array I mean arrays in my experimental language, not in C++) How can I fit the array concept into the Value class above? Is it possible? How should I make arrays able to be passed around just as you could pass around integers and strings in my language, using the class above? Accessing array elements or memory allocation wouldn't be the problem, I just don't know how to store them.

    Read the article

  • What data/service is where?

    - by MrTelly
    What management tools (open source or otherwise) are there to track the location of data, the services that deliver/use that data and the services themselves. If you believe the snake oil a combination of DB, ESB and SOA will deliver anything anywhere, but how do you know what's where. BTW I'm not interested at the WSDL level, I'm thinking of a tool that the users/BA community would populate and use. A combination of SOA and Database is now the bedrock of most applications, however what used to be called Data Dictionaries, and would now be Service Catalogues? or MetaData repositories still seem to live in purely DataCentric world.

    Read the article

  • What's the best way of using a pair (triple, etc) of values as one value in C#?

    - by Yacoder
    That is, I'd like to have a tuple of values. The use case on my mind: Dictionary<Pair<string, int>, object> or Dictionary<Triple<string, int, int>, object> Are there built-in types like Pair or Triple? Or what's the best way of implementing it? Update There are some general-purpose tuples implementations described in the answers, but for tuples used as keys in dictionaries you should additionaly verify correct calculation of the hash code. Some more info on that in another question. Update 2 I guess it is also worth reminding, that when you use some value as a key in dictionary, it should be immutable.

    Read the article

  • Using list comprehension in Python to do something similar to zip()?

    - by jamieb
    I'm a Python newbie and one of the things I am trying to do is wrap my head around list comprehension. I can see that it's a pretty powerful feature that's worth learning. cities = ['Chicago', 'Detroit', 'Atlanta'] airports = ['ORD', 'DTW', 'ATL'] print zip(cities,airports) [('Chicago', 'ORD'), ('Detroit', 'DTW'), ('Atlanta', 'ATL')] How do I use list comprehension so I can get the results as a series of lists within a list, rather than a series of tuples within a list? [['Chicago', 'ORD'], ['Detroit', 'DTW'], ['Atlanta', 'ATL']] (I realize that dictionaries would probably be more appropriate in this situation, but I'm just trying to understand lists a bit better). Thanks!

    Read the article

  • How do I know if I'm iterating on the last item of the collection?

    - by Camilo Martin
    I want to do something different on the last KeyValuePair of the Dictionary I'm iterating on. For Each item In collection If ItsTheLastItem DoX() Else DoY() End If Next Is this possible? Edit: As Jon correctly remarks, Dictionaries are not the kind of thing that's sorted, so I should mention that I only want to do this when displaying results to the user, and it doesn't matter if later on the last item is different. In another note, I'll use my own answer but I'll accept the most upvoted one after I check back in some hours.

    Read the article

  • Python and database

    - by axl456
    hello.. Am working on a personal project, where i need to manipulate values in a database-like format.. Up until now, am using dictionaries, tuples, and list to store and consult those values. Am thinking about starting to use SQL to manipulate those values, but I dont know if its worth the effort, because I dont know anything about SQL, and I dont want to use something that wont bring me any benefits (if I can do it in a simpler way, i dont want to complicate things) if am only storing and consulting values, what would be the benefit of using SQL? PS: the numbers of row goes between 3 and 100 and the number of columns is around 10 (some may have 5 some may have 10 etc)

    Read the article

  • Python: Data Object or class

    - by arg20
    I enjoy all the python libraries for scraping websites and I am experimenting with BeautifulSoup and IMDB just for fun. As I come from Java, I have some Java-practices incorporated into my programming styles. I am trying to get the info of a certain movie, I can either create a Movie class or just use a dictionary with keys for the attributes. My question is, should I just use dictionaries when a class will only contain data and perhaps almost no behaviour? In other languages creating a type will help you enforce certain restrictions and because of type checks the IDE will help you program, this is not always the case in python, so what should I do? Should I resort to creating a class only when there's both, behaviour and data? Or create a movie class even though it'll probably be just a data container? This all depends on your model, in this particular case either one is fine but I'm wondering about what's a good practice.

    Read the article

  • Help need for openfast implementation

    - by ganuke
    Our stock exchange going to implement FAST messaging in their system in order to reduced the bandwidth usage. We have already implement the FIX based application to trade with Stock exchange. In future we need implement FIX FAST in our application to communicate with them. I found that OPEN FAST is FAST based library. But I do not have any idea how to start with it. I went through OpenFast web site but could not find much support on how to use templates and dictionaries. Can some one guide me or provide some resources to start with? Thanks in advance.

    Read the article

  • What is the pythonic way to add type information to an object's attributes?

    - by Tikitu
    I'm building classes where I know the types of the attributes, but Python of course doesn't. While it's un-pythonic to want to tell it, supposing I do want to, is there an idiomatic way to do so? Why: I'm reading in serialised data (without type information) involving objects-nested-inside-objects. It's easy to put it into nested dictionaries, but I want it in objects of my class-types, to get the right behaviours as well as the data. For instance: suppose my class Book has an attribute isbn which I will fill with an ISBNumber object. My serialised data gives me the isbn as a string; I would like to be able to look at Book and say "That field should be filled by ISBNumber(theString)." Bonus glee for me if the solution can be applied to classes I get from someone else without editing their code.

    Read the article

  • How do I transfer configuration data into injected objects?

    - by louis
    I used to use Spring.Net and want to switch to Ninject 1.5 (I have to use .NET2, since some unlucky guy like me still needs to consider users working with win 2k). I used to have everything done in xml and only invoke the container during startup. In this way, only very limited codes are depending on container. I have scenarios like this and I wonder how to do the same in Ninject. I have external config file, which are the items the end users can change basing on their environment/preferences. And some of my objects depends on those values to initialize. Mostly they are primary values, but some times can be list/dictionaries/etc.

    Read the article

  • Display values and how many times they occured using a Dictionary

    - by user1730056
    I've been told to By using a dictionary (or your solution to Part 4), write a method at_least(a, n) that takes a list, a, and an integer, n, as arguments and returns a list containing only the elements of a that occur at least n times. For complete marks, the list should contain the elements in order of their first occurrence in a. I was able to figure this without using a dictionary, with def at_least2(a, n): return [x for x in a if a.count(x) is n] I was wondering how I can write this using a dictionary? The input is: a = [-6, 8, 7, 3, 2, -9, 1, -3, 2, -4, 4, -8, 7, 8, 2, -2, -7, 0, 1, -9, -3, -7, -3, -5, 6, -3, 6, -3, -10, -8] def at_least(a, 2): and the output: [8, 7, 2, -9, 1, -3, 2, -8, 7, 8, 2, -7, 1, -9, -3, -7, -3, 6, -3, 6, -3, -8] Edit: I don't understand how a dictionary is being used, yet the output isn't in dictionary form? My understanding is that dictionaries have values for each object. I'm not sure if I'm using the right terms.

    Read the article

  • Application.Current changes when using reflection to create an instance of another Application class

    - by markti
    Let's say I have the following Silverlight Applications: App1.xap App2.xap App3.xap Let's say that I start App1.xap as the default xap file. If I load App2.xap and App3.xap and instantiate an Application class within one of the other two XAPs. The Application.Current changes to be that new instance. System.Windows.Application obj = Activator.CreateInstance(type) as System.Windows.Application; I don't want the current application to change. I just want to get the merged Resource Dictionaries off the Application class.

    Read the article

  • Please help me convert this C# 2.0 snippet to Linq.

    - by Hamish Grubijan
    This is not a homework ;) I need to both A) optimize the following code (between a TODO and a ~TODO) and B) convert it to [P]Linq. Better readability is desired. It might make sense to provide answers to A) and B) separately. Thanks! lock (Status.LockObj) { // TODO: find a better way to merge these dictionaries foreach (KeyValuePair<Guid, Message> sInstance in newSInstanceDictionary) { this.sInstanceDictionary.Add(sInstance.Key, sInstance.Value); } foreach (KeyValuePair<Guid, Message> sOperation in newSOperationDictionary) { this.sOperationDictionary.Add(sOperation.Key, sOperation.Value); } // ~TODO }

    Read the article

  • Static dictionary in .Net Thread safety

    - by Emmanuel
    Reading msdn documentation for dictionaries it says : "Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe." Those this mean that with a dictionary such as this : static object syncObject = new object(); static Dictionary<string,MyObject> mydictionary= new Dictionary<string, MyObject>(); Is doing something like the code below unnecessary? lock (syncObject) { context = new TDataContext(); mydictionary.Add("key", myObject); }

    Read the article

  • How to improve the speed of a loop containing a sqlalchemy query statement as conditional

    - by LtPinback
    This loop checks if a record is in the sqlite database and builds a list of dictionaries for those records that are missing and then executes a multiple insert statement with the list. This works but it is very slow (at least i think it is slow) as it takes 5 minutes to loop over 3500 queries. I am a complete newbie in python, sqlite and sqlalchemy so I wonder if there is a faster way of doing this. list_dict = [] session = Session() for data in data_list: if session.query(Class_object).filter(Class_object.column_name_01 == data[2]).filter(Class_object.column_name_00 == an_id).count() == 0: list_dict.append({'column_name_00':a_id, 'column_name_01':data[2]}) conn = engine.connect() conn.execute(prices.insert(),list_dict) conn.close() session.close() edit: I moved session = Session() outside the loop. Did not make a difference.

    Read the article

  • What's a good way to have sample data on the iPhone/iPad?

    - by MikeN
    I have an iPad application that pulls in all of its data from an external web service. I am working on building in a demo mode that will use a cache of demo data stored on the device so it can be demoed and tried out without the web service connection (or an internet connection.) Is there a project or good practices standard to follow to model this type of sample data? I'm expecting JSON arrays/Dictionaries back from my web service, how could I build a function that uses hardcoded data to create the NSMutableData object I'd expect to get back from a JSON web request?

    Read the article

  • Multiple levels of 'collection.defaultdict' in Python

    - by Morlock
    Thanks to some great folks on SO, I discovered the possibilities offered by collections.defaultdict, notably in readability and speed. I have put them to use with success. Now I would like to implement three levels of dictionaries, the two top ones being defaultdict and the lowest one being int. I don't find the appropriate way to do this. Here is my attempt: from collections import defaultdict d = defaultdict(defaultdict) a = [("key1", {"a1":22, "a2":33}), ("key2", {"a1":32, "a2":55}), ("key3", {"a1":43, "a2":44})] for i in a: d[i[0]] = i[1] Now this works, but the following, which is the desired behavior, doesn't: d["key4"]["a1"] + 1 I suspect that I should have declared somewhere that the second level defaultdict is of type int, but I didn't find where or how to do so. The reason I am using defaultdict in the first place is to avoid having to initialize the dictionary for each new key. Any more elegant suggestion? Thanks pythoneers!

    Read the article

  • Python - Is it possible to get the name of the chained function?

    - by user1326876
    I'm working on a class that basically allows for method chaining, for setting some attrbutes for different dictionaries stored. The syntax is as follows: d = Test() d.connect().setAttrbutes(Message=Blah, Circle=True, Key=True) But there can also be other instances, so, for example: d = Test() d.initialise().setAttrbutes(Message=Blah) Now I believe that I can overwrite the "setattrbutes" function; I just don't want to create a function for each of the dictionary. Instead I want to capture the name of the previous chained function. So in the example above I would then be given "connect" and "initialise" so I know which dictionary to store these inside. I hope this makes sense. Any ideas would be greatly appreciated :)

    Read the article

  • How much RAM used by Python dict or list?

    - by Who8MyLunch
    My problem: I am writing a simple Python tool to help me visualize my data as a function of many parameters. Each change in parameters involves a non-trivial amount of time, so I would like to cache each step's resulting imagery and supporting data in a dictionary. But then I worry that this dictionary could grow too large over time. Most of my data is in the form of Numpy arrays. My question: How would one go about computing the total number of bytes used by a Python dictionary. The dictionary itself may contain lists and other dictionaries, each of which contain data stored in Numpy arrays. Ideas?

    Read the article

  • is vim able to detect in which language a file is written, and then load the correct dictionnary ?

    - by Niels
    I am using several languages, and by now I am obliged to indicate vim with which of these the spell check must be done. Is there a way to set up vim so that he automatically detects the correct one ? I remember vaguely that in a previous version of vim, when the spell check was not integrated, this was possible, using the vimspell script. It would be even better if this could apply not only to a file but also to a portion of a file, since I frequently mix several languages in a single file. Of course, I would like to avoid to load several dictionaries simultaneously.

    Read the article

  • Is "programmatically" a word? [closed]

    - by Lo'oris
    I can't find it on any of the online dictionaries I know: dict.org, word reference, urban dictionary, oxford paravia, garzanti. To my ears of a non-native speaker, it sounds horrible. Actually it sounds like a word made-up by another non-native speaker that wanted to say something, didn't know how, and just hacked in a word of his language. The only place I've read it other then user-created-content is the android documentation, so this might or might not be related. Do you happen to know where did it start to be used, why by did it spread so much, what does it really mean?

    Read the article

  • Python: What's a correct and good way to implement __hash__()?

    - by random-name
    What's a correct and good way to implement hash()? I am talking about the function that returns a hashcode that is then used to insert objects into hashtables aka dictionaries. As hash() returns an integer and is used for "binning" objects into hashtables I assume that the values of the returned integer should be uniformly distributed for common data (to minimize collisions). What's a good practice to get such values? Are collisions a problem? In my case I have a small class which acts as a container class holding some ints, some floats and a string.

    Read the article

  • Is vim able to detect the natural language of a file, then load the correct dictionary ?

    - by Niels
    I am using several languages, and currently I am obliged to indicate to vim with which of these the spell check must be done. Is there a way to set up vim so that it automatically detects the correct one? I vaguely remember that in a previous version of vim, when the spell check was not integrated, the vimspell script made this possible. It would be even better if this could apply not only to a file but also to a portion of a file, since I frequently mix several languages in a single file. Of course, I would like to avoid to load several dictionaries simultaneously.

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15  | Next Page >