tuples

django: TypeError: 'tuple' object is not callable

元气小坏坏 提交于 2020-05-22 19:22:27
问题 Getting a type error, 'tuple' object is not callable. Any idea what it could be? (dont worry about the indentation. It copies in weird.) I'm trying to create choices based on PackSize of storeliquor. Views.py: def storeliquor(request, store_id, liquor_id): a = StoreLiquor.objects.get(StoreLiquorID=liquor_id) s = Store.objects.get(StoreID=store_id) x = Order.objects.get(storeID=s, Active=True) y = a.OffPremisePrice c = a.BottleSize g = request.POST.get('OrderAmount', '') b = a.PackSize h = b*2

Remove overlapping numbers from inside a tuple in python such that no 2 tuples have the same starting or ending number

落花浮王杯 提交于 2020-05-17 06:05:14
问题 I have a list of tuples. Each tuple consists of a string and a dict. Now each dict in that, consists of a list of tuples. The size of the list is around 8K entries. Sample data: dataset = [('made of iron oxide', {'entities': [(12, 16, 'PRODUCT'), (17, 20, 'PRODUCT'), (15, 24, 'PRODUCT'), (12, 19, 'PRODUCT')]}),('made of ferric oxide', {'entities': [(10, 15, 'PRODUCT'), (12, 15, 'PRODUCT'), (624, 651, 'PRODUCT'), (1937, 1956, 'PRODUCT')]})] From here output expected is: dataset = [('made of

Remove overlapping numbers from inside a tuple in python such that no 2 tuples have the same starting or ending number

三世轮回 提交于 2020-05-17 06:04:21
问题 I have a list of tuples. Each tuple consists of a string and a dict. Now each dict in that, consists of a list of tuples. The size of the list is around 8K entries. Sample data: dataset = [('made of iron oxide', {'entities': [(12, 16, 'PRODUCT'), (17, 20, 'PRODUCT'), (15, 24, 'PRODUCT'), (12, 19, 'PRODUCT')]}),('made of ferric oxide', {'entities': [(10, 15, 'PRODUCT'), (12, 15, 'PRODUCT'), (624, 651, 'PRODUCT'), (1937, 1956, 'PRODUCT')]})] From here output expected is: dataset = [('made of

Scala Map, ambiguity between tuple and function argument list

风流意气都作罢 提交于 2020-05-14 17:56:50
问题 val m = scala.collection.mutable.Map[String, Int]() // this doesn't work m += ("foo", 2) // this does work m += (("foo", 2)) // this works too val barpair = ("bar", 3) m += barpair So what's the deal with m += ("foo" , 2) not working? Scala gives the type error: error: type mismatch; found : java.lang.String("foo") required: (String, Int) m += ("foo", 2) ^ Apparently Scala thinks that I am trying to call += with two arguments, instead of one tuple argument. Why? Isn't it unambiguous, since I

hashing different tuples in python give identical result

冷暖自知 提交于 2020-05-10 09:54:16
问题 I'm working with sets of integer matrices, and I thought representing them as tuples made sense, as they are hashable. However the hash() function gave me strange results for tuples: hash(((1, -1, 0), (1, 0, 0), (1, 0, -1))) Out[147]: -697649482279922733 hash(((1, 0, -1), (1, 0, 0), (1, -1, 0))) Out[148]: -697649482279922733 As you can see, these two different tuples have the same hash value. Note that they are actually pretty similar (exchange of the first and last subtuples), however I

Javascript: using tuples as dictionary keys

无人久伴 提交于 2020-05-10 03:39:05
问题 I have a situation where I want to create a mapping from a tuple to an integer. In python, I would simply use a tuple (a,b) as the key to a dictionary, Does Javascript have tuples? I found that (a,b) in javascript as an expression just returns b (the last item). Apparently this is inherited from C. So, as a workaround, I thought I can use arrays instead, my_map[[a,b]] = c I tried it at the Firebug console and it seemed to work. Is that a good way to do it? Another alternative I thought of is

Voronoi not plotting real time data tuple index out of range

╄→尐↘猪︶ㄣ 提交于 2020-05-09 17:15:07
问题 I'm trying to plot a voronoi diagram with real time data, but get the error: IndexError: tuple index out of range the code: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes data = str(data, "utf-8") #convert bytes into string and fix the 'b' #data.decode("utf-8", errors="ignore") data = data.strip(" ").split(".") x = data[0] y = data[1] x = float(x.replace( ',', '.')) y = float(y.replace( ',', '.')) vor = Voronoi(x,y) The value of the data variable is like this: [b' 0,2036377.2

Find a specific tuple element in a vector of tuples?

混江龙づ霸主 提交于 2020-05-08 14:32:06
问题 I am having an issue with finding a tuple element, in a vector of tuples. I have a vector<tuple<int,int,int,int>> in which I need to find the position in the vector where get<0>(vector) = 0 . I need the position, as I need to extract the other values from the tuple in that position as well. The value of get<0> is unique and will only occur once in the vector. How do I do that? 回答1: You should use the std::find_if algorithm; std::vector<std::tuple<int,int,int,int>> v = {{0,1,2,3},{1,2,3,4},{2

Find a specific tuple element in a vector of tuples?

别等时光非礼了梦想. 提交于 2020-05-08 14:32:05
问题 I am having an issue with finding a tuple element, in a vector of tuples. I have a vector<tuple<int,int,int,int>> in which I need to find the position in the vector where get<0>(vector) = 0 . I need the position, as I need to extract the other values from the tuple in that position as well. The value of get<0> is unique and will only occur once in the vector. How do I do that? 回答1: You should use the std::find_if algorithm; std::vector<std::tuple<int,int,int,int>> v = {{0,1,2,3},{1,2,3,4},{2

How to sort a list of tuples by their first element?

試著忘記壹切 提交于 2020-05-08 06:37:18
问题 I have a list of tuples: self.gridKeys = self.gridMap.keys() # The keys of the instance of the GridMap (It returns the product of every possible combination of positions in the specified grid, in tuples.) print self.gridKeys self.gridKeys: [(7, 3), (6, 9), (0, 7), (1, 6), (3, 7), (2, 5), (8, 5), (5, 8), (4, 0), (9, 0), (6, 7), (5, 5), (7, 6), (0, 4), (1, 1), (3, 2), (2, 6), (8, 2), (4, 5), (9, 3), (6, 0), (7, 5), (0, 1), (3, 1), (9, 9), (7, 8), (2, 1), (8, 9), (9, 4), (5, 1), (7, 2), (1, 5),