tuples

How do I store version number strings in a django database so they are correctly comparable/sortable

泪湿孤枕 提交于 2019-12-06 02:05:36
I'm developing/maintaining/curating a database of test results gathered from various wearable research devices. Each device has three main components, each of which has two version numbers (firmware and hardware). I'm using a django app to provide a web interface to the database. The version numbers represented either as straight integers, or as triplets (Major, minor, build). The integers are easy enough to handle, and I can obviously store the triplets as strings, but as strings they won't sort correctly or compare correctly, for example if I want only test results produced by devices with

How can I iterate over only the first variable of a tuple

蓝咒 提交于 2019-12-06 01:48:42
问题 In python, when you have a list of tuples, you can iterate over them. For example when you have 3d points then: for x,y,z in points: pass # do something with x y or z What if you only want to use the first variable, or the first and the third. Is there any skipping symbol in python? 回答1: Is something preventing you from not touching variables that you're not interested in? There is a conventional use of underscore in Python to indicate variable that you're not interested. E.g.: for x, _,_ in

swap temporary tuples of references

不羁岁月 提交于 2019-12-06 01:43:25
问题 I'm writing a custom iterator that, when dereferenced returns a tuple of references. Since the tuple itself is ephemeral, I don't think I can return a reference from operator*(). I think my iterator makes sense semantically, since it has reference semantics, even though operator* returns a value. The issue is, when I try to call std::swap (or rather, when std::sort does), like below, I get errors because the swap expects l-values. Is there an easy fix to this problem? #include <vector> class

Sort an array of tuples in swift 3

梦想的初衷 提交于 2019-12-06 01:22:02
Hi I have the following class MyClass { var myString: String? } var myClassList = [String: MyClass]() I would like to sort this array alphabetically by the myString variable in Swift 3 any pointers? Cool problem! Though i'd like to point out first that [String: MyClass] is a Dictionary and not at Tupule. Swift does, however, support Tupules. The syntax for your tupule would look like so: var tupule: (String, MyClass) = (foo, bar) You would then need to make an Array of them: var tupules:[(String, MyClass)] = [(foo, bar), (up, dog)] Then you could sort that array: tupules.sort({ $0[1].myString

How Do I Use A Tuple Properly in ASP.NET MVC 4

不羁的心 提交于 2019-12-06 00:59:22
I'm trying to use two models in one view using a tuple but I'm getting this error: Server Error in '/' Application. The model item passed into the dictionary is of type 'PagedList.PagedList 1[S00117372CA3.Product]', but this dictionary requires a model item of type 'System.Tuple 2[PagedList.IPagedList 1[S00117372CA3.Product],System.Collections.Generic.IEnumerable 1[S00117372CA3.Order]]'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception

Why can I only append an array of tuples using tuple names directly if the values are `let` constants — Swift

两盒软妹~` 提交于 2019-12-05 23:58:55
Here's an example of what I'm talking about: typealias SomeTuple = (string: String, int: Int) var tupleArray: [SomeTuple] = [] // Fails // tupleArray.append(string: "Hello", int: 42) // Works let string = "Hello" let num = 42 tupleArray.append(string: string, int: num) // Fails // var varString = "Hi Again" // var varNum = 234 // tupleArray.append(string: varString, int: varNum) Why does the .append(tupleName: val, anotherTupleName: anotherVal) syntax only work when the values are declared previously as let constants? Note: I'm aware that I could wrap my tuples in an extra parenthetical like

A Faster Nested Tuple to List and Back

三世轮回 提交于 2019-12-05 23:52:42
I'm trying to perform tuple to list and list to tuple conversions on nested sequences of unknown depth and shape. The calls are being made hundreds of thousands of times, which is why I'm trying to squeeze out as much speed as possible. Any help is much appreciated. Here's what I have so far... def listify(self, seq, was, toBe): temp = [] a = temp.append for g in seq: if type(g) == was: a(self.listify(g, was, toBe)) else: a(g) return toBe(temp) And a call for tuple to list would look like this: self.listify((...), tuple, list) Edit: Yeah, I totally missed both the enumerate (from an old

Deserialize JSON array of arrays into List of Tuples using Newtonsoft

牧云@^-^@ 提交于 2019-12-05 23:51:58
问题 I am receiving data that looks like this from an online service provider: { name: "test data", data: [ [ "2017-05-31", 2388.33 ], [ "2017-04-30", 2358.84 ], [ "2017-03-31", 2366.82 ], [ "2017-02-28", 2329.91 ] ], } I would like to parse it into an object that looks like this: public class TestData { public string Name; public List<Tuple<DateTime, double>> Data; } The only thing I have been able to find is how to parse an array of objects into a list of tulples, for example: Json.NET

Haskell List of Tuple Search

纵饮孤独 提交于 2019-12-05 23:38:06
问题 I have a list of tuples like this: [("username", 123), ("df", 54), ("as",2 34)] I need to search the value based on username. I have using lookup but i need to change the value of the integer and write back to file. My logic of this is to delete the tuple and insert another new tuple value rather than change it. Any idea how to do this ? 回答1: Use Data.Map like this : import qualified Data.Map as Map m1 :: Map String Int m1 = Map.fromList [("username", 123), ("df", 54), ("as",234)] Let's

to slice columns in a tuple present in a numpy array

不羁的心 提交于 2019-12-05 22:59:52
I have imported a text file into a numpy array as shown below. data=np.genfromtxt(f,dtype=None,delimiter=',',names=None) where f contains the path of my csv file now data contains the following. array([(534, 116.48482, 39.89821, '2008-02-03 00:00:49'), (650, 116.4978, 39.98097, '2008-02-03 00:00:02'), (675, 116.31873, 39.9374, '2008-02-03 00:00:04'), (715, 116.70027, 40.16545, '2008-02-03 00:00:45'), (2884, 116.67727, 39.88201, '2008-02-03 00:00:48'), (3799, 116.29838, 40.04533, '2008-02-03 00:00:37'), (4549, 116.48405, 39.91403, '2008-02-03 00:00:42'), (4819, 116.42967, 39.93963, '2008-02-03