Hello, I have this home work question to be solved on a cloud ide: Create a class called ShoppingCart. Create a constructor that takes no arguments and sets the total attribute to zero, and initializes an empty dict attribute named items. Create a method add_item that requires item_name, quantity and price arguments. This method should add the cost of the added items to the current value of total. It should also add an entry to the items dict such that the key is the item_name and the value is the quantity of the item. Create a method remove_item that requires …

Member Avatar
Member Avatar
+0 forum 4

hi! i want to place the contents of a dictionary into a csv file. Can someone help me with this? i already have the code in reading the csv file [CODE] import csv reader = csv.reader(open("c:\sample.dat")) for row in reader: print row [/CODE] i want the first element of the row be the key for the dictionary so that if i access the dictionary again using the key i'll be able to get the different of the rows of that dictionary. I just don't know how to use loop thru the csv rows and put it in the dictionary and …

Member Avatar
Member Avatar
+0 forum 20

Here is the CSV file that I am working with: `"A","B","C","D","E","F","G","H","I","J" "88",18,1,"<Req TID=""34"" ReqType=""MS""><IISO /><CID>2</CID><MemID>0000</MemID><MemPass /><RequestData><S>[REMOVED]</S><Na /><La /><Card>[REMOVED]</Card><Address /><HPhone /><Mail /></ReqData></Req>","<Response T=""3"" RequestType=""MS""><MS><Memb><PrivateMembers /><Ob>0-12-af</Ob><Locator /></Memb><S>[REMOVED]</S><CNum>[REMOVED]</CNum><FName /><LaName /><Address /><HPhone /><Email /><IISO /><MemID /><MemPass /><T /><CID /><T /></MS></Response>",0-JAN-10 12.00.02 AM,27-JUN-15 12.00.00 AM,"26",667,0 "22",22,1,"<Req TID=""45"" ReqType=""MS""><IISO /><CID>4</CID><MemID>0000</MemID><MemPass /><RequestData><S>[REMOVED]</S><Na /><La /><Card>[REMOVED]</Card><Address /><HPhone /><Mail /></ReqData></Req>","<Response T=""10"" RequestType=""MS""><MS><Memb><PrivateMembers /><Ob>0-12-af</Ob><Locator /></Memb><S>[REMOVED]</S><CNum>[REMOVED]</CNum><FName /><LaName /><Address /><HPhone /><Email /><IISO /><MemID /><MemPass /><T /><CID /><T /></MS></Response>",0-JAN-22 12.00.02 AM,27-JUN-22 12.00.00 AM,"26",667,0 "32",22,1,"<Req TID=""15"" ReqType=""MS""><IISO /><CID>45</CID><MemID>0000</MemID><MemPass /><RequestData><S>[REMOVED]</S><Na /><La /><Card>[REMOVED]</Card><Address /><HPhone /><Mail /></ReqData></Req>","<Response T=""10"" RequestType=""MS""><MS><Memb><PrivateMembers /><Ob>0-12-af</Ob><Locator /></Memb><S>[REMOVED]</S><CNum>[REMOVED]</CNum><FName /><LaName /><Address /><HPhone /><Email /><IISO /><MemID /><MemPass /><T /><CID /><T /></MS></Response>",0-JAN-20 12.00.02 AM,27-JUN-34 12.00.00 AM,"26",667,0` The below …

Member Avatar
+0 forum 0

I found that one can use dictionaries to hold Tkinter widget config and display parameters. This then permits one to have these dictionaries elsewhere in the code for easy modification instead of buried within the code for each widget. I particularly like to place these dictionaries toward the top of my Tkinter code for easy access and modification. I no longer have to search through a long display of widget code, and then over to the pertinent parameter to modify what I need. I now just find the pertinent dictionary in the area of focus--congfig. or display--and modify it. "Easy …

Member Avatar
+0 forum 0

Part 2 of exploring/tasting the Swift language takes a look at dictionaries; process flow controls like loops, if/else and switch/case; functions and sorting. I hope I can follow this up with part 3, a closer look at class operations.

Member Avatar
Member Avatar
+2 forum 23

The example shows how to establish a dictionary of (row, column):value pairs to mimic a two dimensional array. This can be easily expanded to more dimensions. Python3 has dictionary comprehension, making the process of creating a dictionary of this type easier.

Member Avatar
Member Avatar
+1 forum 9

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

Hi guys, I am trying to write a program which picks the closest number possible out of a dictionary. The dictionary contains 50 doubles values, and I use a random double to pick the number i want to get the closest to if that makes sense. Currently I am using linq to pick the first one which is less or equal to the random number. The problem I have found with this is that it is not reaching numbers which are closer and its most certainly picks the same key all the time. I have also tried the SkipWhile method …

Member Avatar
Member Avatar
+0 forum 4

I have been trying to create a program which the teacher log in to view the scores of a test of a school class. The scores are stored in a text file like this: Charlotte:7 Charlotte:4 Charlotte:3 Chelsea:2 Chelsea:9 Chelsea:5 Jeff:1 Jeff:10 As you can see there are multiple scores for each student, I need to be able to sort these scores by highest score out of the class with each student's highest score. I've worked out how to sort it by each student's highest score with the following code but I now need to sort those highest scores of …

Member Avatar
Member Avatar
+0 forum 5

Hi Guys, Im a bit puzzled on the best way to store data which will later be saved to a csv. I am doing a record search on a database table which will get cycle through each employee and get the relevent information. Once I have done this I will then create a string builder which will go through all this information and append the csv. The problem is im struggling to find the best way to store this information in the meantime. Ive tried something funky with a list dictionary but it didnt come off right. Any ideas anyone? …

Member Avatar
Member Avatar
+0 forum 5

I uploaded a module named [symboldict](https://pypi.python.org/pypi/symboldict) to the python package index (pypi). This snippet shows how to use it to create a dictionary of symbols from various modules. This dictionary can be used as a common language shared by several modules. It can be used to load python libraries in a lazy way. It also brings the power of python dictionaries to manipulate collections of functions.

Member Avatar
Member Avatar
+4 forum 1

Hello All, I am working on writing a code to implement dictionary in C++. I have few functions to implement for my dictionary. Can someone please help me writing the definitions for my dictionary. Header file and cpp file is attached here. **Dict.h file is as below:** enum WordType{All, Animal, Fruit, Name}; struct Word{ WordType type; char word[20]; }; struct Dict{ int size; int capacity; Word **wordArray; }; Dict *createDictionary(int capacity); bool addWord(Dict *dic, const char *word, WordType type); void deleteDictionary(Dict *dic); void printDictionary(Dict *dic, WordType type=All); **Dict.cpp file** is as below in which I need to add definitions: #include …

Member Avatar
Member Avatar
+0 forum 7

The idea for this snippet came from vegaseat, who wrote a very nifty RPN calculator in Python, simulating a switch/case statement, something that Python is missing. See this code on page 19 in the projects for beginners thread on the Python software development forum. In my opinion, he did a very good job. So I posed myself a goal: write something equal in C# and, although it was tempting to use: don’t use a case statement. Here is the result. The only thing that C# seems to lack here is the use of variable parameters. One could play with different …

Member Avatar
Member Avatar
+1 forum 4

hi, I need to copy a dictionary to another dictionary where the Dictionary contains class data as value for eg I want to copy the data of object A1 to A2 .Thanks for your time. Class A { } Class B { } Main() { Dictionary<int,A> A1 = new Dictionary<int,A>(); // first dictionary obj Dictionary<int,B> A2 = new Dictionary<int,B>(); // Second dictionary obj }

Member Avatar
Member Avatar
+0 forum 1

Here's a simple tutorial on dictionaries in Python: Dictionaries: Dictionaries are similar to other compound types except that they can use any immutable type as an index. One way to create a dictionary is to start with the empty dictionary and add items. The empty dictionary is denoted {}: [CODE]end2sp = {} end2sp[ "one" ] = "uno" end2sp[ "two" ] = "dos"[/CODE] We can print the current value of the dictionary in the usual way: [CODE]print eng2sp # --> { "one":"uno", "two":"dos" }[/CODE] The elements of a dictionary appear in a coma-separated list. Each entry contains an index and a …

Member Avatar
Member Avatar
+5 forum 16

file_spellcheck = input("Name of the document to be spell-checked: ") with open(file_spellcheck, "r") as i: spellchecking = i.read() for item in spellchecking: items = item.split() if items in with open("file.out", "w") as i: i.write() I need to make a spell checker that uses another file as a dictionary. So let's say the dictionary is words.dat, then the user is prompted to name a document to spell check. User enters a document to spell check, but the program should prompt the user with the word that is spelled incorrectly to either replace, replace all, ignore, ignore all or exit. I got …

Member Avatar
Member Avatar
+0 forum 1

I'm trying to create a program that will prompt the user for a list of text files to read from, then read those text files and build a dictionary of all the unique words found. Then finally put those unique words into another file and make it alphabetical order from string import punctuation def unique_words(sentence, number): return [w for w in set(sentence.translate(punctuation).lower().split()) if len(w) >= number] print (unique_words("This text is a sample text. It need to be parsed correctly.", 2)) I figured out how to make take the unique words out of a sentence but that's it. Can anyone help …

Member Avatar
Member Avatar
+0 forum 11

I have a dictionary [CODE]dict1={'18':['4000','1234'],'12':['7000','4821','187','1860','123','9000']}[/CODE] I want to sort the keys and values such that, the output is, [CODE]dict1={'12':['123','187','1860','4821','7000','9000'],'18':['1234','4000']}[/CODE] I tried something! but it didn work [CODE]>>> for values in dict1: ... dict1[values].sort() ... >>> dict1 {'18': ['1234', '4000'], '12': ['123', '1860', '187', '4821', '7000', '9000']}[/CODE] Full sorting happens for values of '18'. The values of '12' are partially sorted. but '18' and '12' are themselves not sorted. I don't know whats happening!

Member Avatar
Member Avatar
+0 forum 10

I currently have five resx files in a XAML and C# application. I would like to convert the .resx files into their own resource dictionary. How do I do that by what code or website to look at? In the App.Xaml, xaml, and C# what is the process?

Member Avatar
Member Avatar
+0 forum 1

What I am trying to do is delete the key value pairs out of a dictionary if the value is = 0. I seem not to be acheiving that so far. Python 2.7.5+ (default, Sep 19 2013, 13:48:49) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = [10, 0, 35, 45, 34, 0, 22, 0] >>> keys = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'] >>> dictionary = dict(zip(keys, a)) >>> dictionary {'Seven': 22, 'Six': 0, 'Three': 35, 'Two': 0, 'Four': 45, 'Five': 34, 'Eight': 0, 'One': 10} >>> {i:dictionary[i] for i …

Member Avatar
Member Avatar
+0 forum 3

Hello everybody...I'm new in C# programming but recently I have a problem and need to solve it. I hope you guys can help me. This problem only can solved with List and Dictionary. [CODE] using System; using System.Collections.Generic; using System.Text; using System.Collections; namespace ApplicantTestin { /// The DataObject class stored with a key class DataObject { // Populate } class Program { static Hashtable Data = new Hashtable(); static string[] StaticData = new string[] { "X-Ray","Echo","Alpha", "Yankee","Bravo", "Charlie", "Delta", "Hotel", "India", "Juliet", "Foxtrot","Sierra", "Mike","Kilo", "Lima", "November", "Oscar", "Papa", "Qubec", "Romeo", "Tango","Golf", "Uniform", "Victor", "Whisky", "Zulu"}; static void Main(string[] args) { …

Member Avatar
Member Avatar
+0 forum 4

Shows you how to create multiple Tkinter buttons in a loop, each with its own name, label and command response.

Member Avatar
Member Avatar
+2 forum 1

The code shows you how to create a persistent to file dictionary of data using the python module shelve.

Member Avatar
Member Avatar
+4 forum 2

Hi, I would like to to to store the Name and Items of ComboBox into dictionary. With the below code,I am able to store them. However, Name of ComboBox is as counting ComboBox10 to ComboBox1n. I would like to store Name of ComboBox as ComboBox1,ComboBox2 rather than ComboBox10 to ComboBox1n for my futher propose. It's not working with _dic.Add(ctl.Name, myCombo.Items(j).ToString) so I have to loop as _dic.Add(ctl.Name & j.ToString, myCombo.Items(j).ToString). Would Appreciate your help and suggestion. If TypeOf ctl Is ComboBox Then myCombo = CType(ctl, ComboBox) For j As Integer = 0 To myCombo.Items.Count - 1 _dic.Add(ctl.Name & j.ToString, myCombo.Items(j).ToString) …

Member Avatar
Member Avatar
+0 forum 5

Hi I am storing name and texts of controls (Label, Button, ComboBox, ListBox, etc.) into a dictionary. With ContainsKey, I am able to find the texts of Labels, Buttons, and RadioButtons. However, I am getting problem to find the items of ComboBox. Appreciate if you have an idea. If _dic.ContainsKey(selectedControl.Name) Then Debug.Print("I found the text """ & _dic(selectedControl.Name) & """")

Member Avatar
Member Avatar
+0 forum 2

Hi , I am able to add Label, button,texboxes into Dictionary. However I am getting problem to add values of Combobox into dictionary. Here is how I was trying to do. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Try Dim myLabel As Label Dim myButton As Button Dim myRadio As RadioButton Dim myCombo As ComboBox = Nothing _dic.Clear() For Each ctl As Control In Me.Controls If TypeOf ctl Is Label Then myLabel = CType(ctl, Label) _dic.Add(ctl.Name, myLabel.Text) ElseIf TypeOf ctl Is Button Then myButton = CType(ctl, Button) _dic.Add(ctl.Name, myButton.Text) ElseIf TypeOf ctl Is RadioButton Then myRadio = …

Member Avatar
Member Avatar
+0 forum 3

Hey I have dictionary like following one dicts = {'met_293': ['81.0175','4','7','7','29.76','23','1','0','22','28.57','2','[KG]EHY'],'met_394': ['79.9579','4','7','7','29.76','18','3','0','15','28.57','2','EHY[ILV]'],'met_309': ['81.0175','4','7','7','29.76','23','1','0','22','28.57','2','[KG]EHY'],'met_387': ['79.9579','4','7','7','29.76','18','3','0','15','28.57','2','EHY[ILV]']} I want to remove keys which have same value like 'met_293' and 'met_309' those two keys have same value at 12th position which is '[KG]EHY' so i want my dictionary like this {'met_293': ['81.0175','4','7','7','29.76','23','1','0','22','28.57','2','[KG]EHY'],'met_394': ['79.9579','4','7','7','29.76','18','3','0','15','28.57','2','EHY[ILV]']} any help!!! thanks

Member Avatar
Member Avatar
+0 forum 2

This code example shows how to create a dictionary with row,column indexed (r,c) key tuples from a typical list of lists 2D matrix. Also an example is shown of the ease of processing the resulting dictionary.

Member Avatar
Member Avatar
+5 forum 4

I have a data set like this data=[{u'a': u'D', u'b': 100.0, u'c': 201L, u'd': datetime.datetime(2007, 12, 29, 0, 0), u'e': datetime.datetime(2008, 1, 1, 6, 27, 41)},{u'a': u'W', u'b': 100.0, u'c': 201L, u'd': datetime.datetime(2007, 12, 29, 0, 0), u'e': datetime.datetime(2008, 2, 4, 6, 27, 41)},{u'a': u'W', u'b': 100.0, u'c': 202L, u'd': datetime.datetime(2007, 12, 30, 0, 0), u'e': datetime.datetime(2008, 1, 1, 4, 20, 44)},{u'a': u'D', u'b': 100.0, u'c': 202L, u'd': datetime.datetime(2007, 12, 30, 0, 0), u'e': datetime.datetime(2008, 3, 11, 6, 27, 41)},{u'a': u'D', u'b': 100.0, u'c': 202L, u'd': datetime.datetime(2007, 12, 30, 0, 0), u'e': datetime.datetime(2008, 5, 8, 11, 2, 41)},{u'a': u'D', u'b': …

Member Avatar
Member Avatar
+0 forum 1

Hello, I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of the worst cars ever made. The file looks something like this: 1958 MGA Twin Cam 1958 Zunndapp Janus 1961 Amphicar 1961 Corvair 1966 Peel Trident 1970 AMC Gremlin 1970 Triumph Stag 1971 Chrysler Imperial LeBaron Two-Door Hardtop The car manufacturer should be the key and a tuple containing the year and the model should be the key's value. I tried the following to just get the contents of the file into a list, but only the very …

Member Avatar
Member Avatar
+0 forum 2

The End.