Posts

Showing posts with the label tuples

c# 7.x using a short name for tuple type

Image
Clash Royale CLAN TAG #URR8PPP c# 7.x using a short name for tuple type Anyways to use shortcuts for Tuple types, but still preserve the names for each item in the Tuple? (I have created the examples in the code below with my comments.) /* This way is desired because it keeps the naming for each item in the Tuple, but incorrect for C# 7.x */ using Employee = (string Name, DateTime StartTime, DateTime LeaveTime, int Id, double Payment); /* This way is correct in C# 7.x grammar, but I lost all the names for the items, and I have to using Item1, Item2 and so on.... */ using Employee = Tuple<string, DateTime, DateTime, int, double>; public class TestFunc { public Employee GetEmployee() { Employee value; value.Name = "Steve"; value.StartTime = new DateTime(); value.EndTime = new DateTime(); return value; } } Is the first one valid C# at all? – john 6 secs ago ...

Tuples, dictionary, and helper function problems in Python

Image
Clash Royale CLAN TAG #URR8PPP Tuples, dictionary, and helper function problems in Python So I had an assignment where I took a list of tuples as an argument such as, [('A', 3), ('C', 4), ('B', 2), ('P', 4)] and I had to compute the overall gpa which is basically ((letter-grade-number * number of credits) / number of credits) . So I had to use a dictionary and my body was composed of 3 parts. The first used a helper function that appended the unweighted grades to a list and used a counter to keep track of all the credits that were taken, the second part was a conditional that returned -1 if all the lists were not considered for grading and the last part finally summed all the values in the appended list and divided it by the total number of credits taken and it works perfectly. ((letter-grade-number * number of credits) / number of credits) -1 Now, my next assignment takes a string as an argument such as: 'Jane A 3 A- 3 F 1#Bob C+ 2 D+ 3 B+ 3#Chris ...