Note: In Python 2.7 use: `from __future__ import print_function` to use examples. In Python, by default, the key and value pairs in a dictionary are stored as hashes, therefore dictionaries do not retain the order in which values were added, and cannot be ordered. v_Dict ={} v_Dict["First"] = 99 v_Dict["Second"] = 45 v_Dict["Third"] = 234 print(v_Dict) ## {'Second': 45, 'Third': 234, 'First': 99} No order at all. To maintain an ordered dictionary one must use the collection module's "OrderedDict()." Normally one would declare a dictionary to be ordered like so: from collections import OrderedDict v_Dict = OrderedDict() v_Dict["First"] = 99 …

Member Avatar
Member Avatar
+1 forum 3

I am doing a little home project to learn more about collections and FileIO. I have made a little racing app where the user enters the racers details all of which are strings, and these details are inserted into a List<T> list and then once the user clicks the 'save' button the contents of the list are extracted to a text file. I have successfully been able to write to the text file however I now want to change this so I am able to append the data to the text file instead of the previous data being overwritten each …

Member Avatar
Member Avatar
+0 forum 3

I have been learning about collections such as arrays and arraylists and lists and have come across the term "interface" a fair bit. I know that an IList is an "interface" but I dont understand what an interface is or does. 1. What is an interface in C#? 2. How does IList differ from List? 3. Where do we use an interface? 4. When do we use an interface in our code? This question is probably a simple one but I am still learning, Thankyou

Member Avatar
Member Avatar
+0 forum 3

I have been learning about the collections namespace in C# so have been doing some little self-made projects to learn. I have made a car race app where you enter in the name, car and place of the racer this is then stored in an array list. I can extract the contents of my array list onto the console window but I would like to know how I can write and save it to a text file (kindof like a mini database). I know that every element stored in an array list is stored as an object therefore casting is …

Member Avatar
Member Avatar
+0 forum 5

It comes in handy of course that you can dynamically adjust the size of a List or Dictionary. But this time I want to use a Dictionary with sizes from 1 to 8. When I have e.g. size 3, it will stay that way. On the net I found a solution to use a wrapper class around a Dictionary, which could do the job. Should I resort to an array instead, or are there still other options?

Member Avatar
Member Avatar
+0 forum 4

I have a few general questions about the Collections class in C#:" 1. Because all elements in an ArrayList are stored as objects do we need to cast them into their respective types before extracting? 2. Array lists are used if the size is adjusted accordinly to elements added and the types do not need to be defined, is this the only advantage over standard arrays? if not then what are some other advantages? 3. Apart from the reason for not knowing the size or types of data to be added, when would we use array lists over standard arrays? …

Member Avatar
Member Avatar
+0 forum 2

If I have an array and an array list: int[] myArray = new int[2]; myArray[0] = 1; myArray[1] = 2; ArrayList myArrayList = new ArrayList(); myArrayList.Add("1st element"); myArrayList.AddRange(myArray); By calling the Addrange() method in myArrayList, does this add the contents of myArray to the second element of myArrayList? If so how do you access the second element of myArray through myArrayList?

Member Avatar
Member Avatar
+0 forum 4

Hi Team, Im reading Collections. It is mentioned that while intialising priority queue, it uses natural ordering by default. But my output is not like that. Below is my code and output. public class BackedCollections { public static void main(String[] args) { PriorityQueue<Integer> pq = new PriorityQueue<Integer>(); pq.offer(3); pq.offer(1); pq.offer(5); pq.offer(2); pq.offer(12); pq.offer(14); pq.offer(0); System.out.println(pq); } } ** OUTPUT ** [0, 2, 1, 3, 12, 14, 5] It Should be [0,1,2,3,5,12,15] right ? Please clarify

Member Avatar
Member Avatar
+0 forum 4

This short snippet shows you how to preprocess a text to remove punctuation marks, then do a word frequency count using Counter() from the Python module collections. Finally, two sorts are applied to display words with matching frequency in alphabetical order.

Member Avatar
+2 forum 0

hi how do i do this problem how do i put this in to an array p.assign(p1, A); p.assign(p1, B); p.assign(p2, _A); p.assign(p2, _B); so that it display as p1 A B p2 _A _B because everytim i call the assign method the array index are going to be 0,0 how do i make it reference to the first variable thanks as in in side the class Proxy p = new Proxy(); p1 & p2 = instance of processor and A B _ & _B = instnce of track amanger

Member Avatar
Member Avatar
+0 forum 2

Working with polymorphism collections, list, arraylists etc. I have a sorted collection that I would like to split based on one of the objects properties. All records > 0 to one; all less than to another. I'm trying to think of the best way to implement this. I'm thinking Comparable/Comparator sorting and then iterating through the collection until I hit 0 and splitting there but it also occurs to me that theres gotta be an easier way.

Member Avatar
Member Avatar
+0 forum 5

import java.util.*; class SampleA { } class SampleB extends SampleA{ } class SampleC extends SampleA{ } class VectorDemo { public static void main(String r[]) { Vector<SampleA> v = new Vector<SampleA>(); v.add(new SampleB()); v.add(new SampleC()); SampleC rect = v.get(2); } } The output says "Incompatible types. Found SampleA, required SampleC. SampleC rect = v.get(2);" My doubt is first of all isn't this like using Wildcard where instead of saying Vector<? extends SampleA> v, we mentioned it a form of Vector<Type> v, which is one of the rules of Wild card which says if only <Type> is mentioned then it can accept …

Member Avatar
Member Avatar
+0 forum 3

Hi, this is my first post here, and I really need some help with my homework. I'm a newbie to Java programming, and I have this assignment: [I]Write an application which reads data from a file about certain items (one row - one item, stored are the integer valued code, amount and name of an item) into one of Java's collections (e.g. Vector, ArrayList or LinkedList). After that, user, from standard input, enters item's code (e.g. 253201) and amount he wants, and program updates the amount of that item in collection, and it displays the message to the user with …

Member Avatar
Member Avatar
+0 forum 1

iam building a training set for spam filtering using java,training set data is given as words in text files in one folder,but im unable to debug whats going wrong in java collections [CODE]/* *folder part 1 conatins various text files having name format * **spmsg***.txt and ***legit***.txt e.g 11927legit569.txt ,106127spmsgc26 * inside it it has contents like Subject: 5581 2005 47 * 1791 80 15184 64 2155 5581 2005 80 21292 10607 47 64 * 209 22910 132 1672 84 3865 84 1570 84 2005 84 10492 1847 12330 4797 82 13886 2170 47 */ package naive_bayes; import java.util.*; import …

Member Avatar
Member Avatar
+0 forum 5

I want to inquire what is the major difference between the usage of ArrayList and Array in the Java programming language. I would appreciate good responses and would be enthralled to continue the discussion further upon interest. Regards, Ali

Member Avatar
Member Avatar
+0 forum 2

Hello I have a problem with my vba collection object. When I run the code below I get the "out of stack space (error 28)" message. It seems to me that my collection shouldnt take up so much memory as the each object in it is just a set of a string and 3 single values. Yet it does. The code works fine if I eliminate ie two properties from the Pik object. Please let me know how to overcome this. [CODE] Sub Purity() Dim All As Range, Some As Range Dim a As Integer, b As Integer Dim Peak …

Member Avatar
+0 forum 0

Hello, I have been trying to migrate some code I have written so I can use the advantages of Collection items in several forms I programmed in Access 2002. I was using an array list to collect information from a machine part and its resulting defect, then display a small summary of all parts as well as general information about the machine being repaired. Now, most of the transition has gone without problems, however, I have hit a snag. When I try to list the collection items in the textbox, they reuse to list correctly. Here is the code I …

Member Avatar
Member Avatar
+0 forum 7

EDIT: Deleted the original question. After reading, I realised that I would have to paste so much additional code that it would take someone a couple of days just to understand what was happening in my own code that it may detract from the issue at hand. Problem: When I add an object to a collection (many-to-many relationship) the object is saved and committed to the database. However, if I then try and retrieve that object somewhere else (on a different thread) the object state is incorrect and the collection does not contain the recently added item. Checking the database …

Member Avatar
Member Avatar
+1 forum 1

I know that technically, an Interface is used for reading and not writting or editing however, I want to add an add and addrange function to the following class, here is what I currently have which is not working [code] public class HrefCollection : IEnumerable<Href> { private IEnumerable<Href> hrefs; public IEnumerable<Href> Add( Href href ) { yield return href; } public IEnumerable<Href> AddRange( List<Href> hrefs ) { foreach( Href href in hrefs ) { yield return href; } } public IEnumerator<Href> GetEnumerator() { return hrefs.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return hrefs.GetEnumerator(); } } [/code] I'm not quite sure how to …

Member Avatar
Member Avatar
+1 forum 4

Hi Group, Need some help. I'm performing some statistics on a txt file that has multiple columns using a collection list (vb.net 2008). My files can contain 100,000+ samples per file. How would I code my function to have it perform work on the first 3000 samples and continue the calculations on every 3000 samples thereafter? Thx! [CODE] Private Sub decimationButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles decimationButton.Click Dim lines() As String = System.IO.File.ReadAllLines(inputFileName) '("TEXT_FILE") Dim list As New List(Of Double()) For Each str As String In lines Dim ele() As Double = Array.ConvertAll(str.Split(vbTab), Function(k) Double.Parse(k)) list.Add(ele) Next …

Member Avatar
Member Avatar
+0 forum 1

Hi I have a static collection class being observed by a number of observers. The objects in the collection are updated when events occur in a 3rd party application and to which the class subscribes. I inform the observers about any changes to the collection, or objects within the collection, by raising an event and passing the object that has changed. I can see that I may run into threading issues with this approach because observers and the 3rd party application all have access to the same object reference. I would be grateful for advice on how to make this …

Member Avatar
+0 forum 0

Hi, Although I have done a reasonable amount of coding I have very little training (self taught) so apologies if this is a stupid question. I have written a basic Defect Management app which allows developers to create a release and assign defects to it. The release object has the usual id, name etc and an object called DefectCollection with is a collection of Defect objects. When I load a Release (using it's load method) it calls the PopulateFromRelease method of the DefectCollection. This all works. However, I now have a ReleaseCollection object which I can populate from a method …

Member Avatar
Member Avatar
+0 forum 3

Hello all, I am getting the following run-time error every time I try to run a program I've converted from Lisp to C#: [QUOTE] System.InvalidCastException was unhandled Message="Unable to cast object of type 'System.Single[]' to type 'System.Collections.Generic.List`1[System.Single]'." [/QUOTE] In the function below the problem is occurring at line 16. The datatypes are all correct and verified elsewhere, so it is not a problem of the mismatched types in the that sense. However, it appears that C# does not allow you to cast an object to a list... I hope that isn't the case, especially since that would mean me rewriting …

Member Avatar
Member Avatar
+1 forum 2

Hi all, and thanks for your help, in advance. I 'm stiing here with 2 choices, and I need help deciding which one to take. I want to take certain factors into account(i.e. efficiency, speed) I have values that I want to place into a SortedMap. I can do this in one of two ways: Every record I want insert has an account number. These are not unique, as one account can have more than one item on its name, i.e. an account number can appear more than once. I have a choice of two ways to put them into …

Member Avatar
+0 forum 0

The End.