tuples

What does “unsupported operand type(s) for -: 'int' and 'tuple'” means?

可紊 提交于 2019-12-06 14:08:23
I got a error saying: unsupported operand type(s) for -: 'int' and 'tuple' How do I correct it? from scipy import integrate cpbar = lambda T: (3.826 - (3.979e-3)*T + 24.558e-6*T**2 - 22.733e-9*T**3 + 6.963e-12*T**4)*8.314 deltahbarCH4 = integrate.quad(cpbar,298,1000) var = deltahbarCH4 hRPbar = hRPbar + (deltahbarCO2 + 2*deltahbarH2O - var -2*deltahbarO2) integrate.quad() returns a tuple ; deltahbarCO2 + 2*deltahbarH2O is an integer, you are trying to subtract the var tuple. If you wanted just the integral y of the integrate.quad() result, use the first element of that tuple: var =

Swift - create a fixed length array enforced at compile time

为君一笑 提交于 2019-12-06 13:16:52
问题 I want to enforce (compile time) array with 5 elements of a particular type I couldn't find a solution so resorted to a workaround by creating a tuple (This is abusive I know) typealias FiveElementArray = (MyType,MyType,MyType,MyType,MyType) // mock array by using typed tuple It works for my needs - until I need to access an element by index at runtime. For instance: var DB = FiveElementArray // the tuple of 5 elements tableView(tableView : UITableView,cellForRowAtIndexPath:indexPath) ->

CFG for python-style tuples

泄露秘密 提交于 2019-12-06 13:13:58
After having read for the zillionth time a question about "How do I parse HTML with Regex" on Stackoverflow, I got myself interested again in grammars, grabbed my university scripts and after a few minutes I wondered how I've ever passed my exams. As a simple (well, "simple" I expected it to be) exercise I tried to write a CFG that produces valid python tuples (for simplicity's sake only using the identifiers a , b and c ). After some good time I now came up with this: G = ( {Tuple, TupleItem, Id}, {“a”, “b”, “c”, “,”, “(“, “)”}, P, Tuple) Being P: Tuple → “(“ TupleItem “)” Tuple → “(“

Working with list of tuples

感情迁移 提交于 2019-12-06 11:49:39
问题 I've been trying to solve this, but I just can't figure it out. So, I've a list with tuples, for example: [("Mary", 10), ("John", 45), ("Bradley", 30), ("Mary", 15), ("John", 10)] and what I want to get is a list with also tuples where, if the name is the same, the numbers of those tuples should be added and, if not, that tuple must be part of the final list too, exemplifying: [("Mary",25), ("John", 55), ("Bradley", 30)] I don't know if I explained myself really well, but I think you'll

tuple_size and an inhereted class from tuple?

自古美人都是妖i 提交于 2019-12-06 11:45:29
I have following code: class TR_AgentInfo : public tuple< long long, //AgentId string, //AgentIp > { public: TR_AgentInfo() {} TR_AgentInfo( const long long& AgentId, const string& AgentIp, ) { get<0>(*this) = AgentId; get<1>(*this) = AgentIp; } long long getAgentId() const { return get<0>(*this); } void setAgentId(const long long& AgentId) { get<0>(*this) = AgentId; } string getAgentIp() const { return get<1>(*this); } void setAgentIp(const string& AgentIp) { get<1>(*this) = AgentIp; } }; Now I want to use this code: int count = tuple_size<TR_AgentInfo>::value; but gcc give this error: error:

Python list_of_tuples: sum second val of each tuple, only if first val of tuple == something

南楼画角 提交于 2019-12-06 10:22:06
问题 I have a list of "tagged" tuples...where each tuple is (tag_id, value)...like so: my_list = [(tag_A, 100), (tag_A, 200), (tag_A, 300), (tag_A, 400), (tag_B, 400), (tag_B, 600)] I want to sum the values of each tuple with the same tag...so that: sum_of_all_values_with_tag_A() = 1000 sum_of_all_values_with_tag_B() = 1000 I can't figure out a simple Pythonic way of doing that. sum(set(value for tag_id, value in my_list)) ...returns the sum of ALL the values. I suppose I can wrap that with a for

How to check a specific type of tuple or list?

走远了吗. 提交于 2019-12-06 09:42:00
Suppose, var = ('x', 3) How to check if a variable is a tuple with only two elements, first being a type str and the other a type int in python? Can we do this using only one check? I want to avoid this - if isinstance(var, tuple): if isinstance (var[0], str) and (var[1], int): return True return False Here's a simple one-liner: isinstance(v, tuple) and list(map(type, v)) == [str, int] Try it out: >>> def check(v): return isinstance(v, tuple) and list(map(type, v)) == [str, int] ... >>> check(0) False >>> check(('x', 3, 4)) False >>> check((3, 4)) False >>> check(['x', 3]) False >>> check(('x'

Haskell Esqueleto project subset of columns to list of custom records

和自甴很熟 提交于 2019-12-06 08:59:32
问题 In all the examples I have seen the results from esqueleto are projected into a list of tuples or to entities records. For example: previousLogItems <- select $ from $ \li -> do orderBy [desc (li ^. LogItemId)] limit 10 return (li ^. LogItemId, li ^. LogItemTitle) Is there any way in esqueleto to project a subset of the columns to custom records (different than the entity) instead of tuples? This being done without an extra projection from tuples to custom records. As an example, let's say

Convert string-tuple to a tuple

耗尽温柔 提交于 2019-12-06 08:25:56
问题 I have an input file with the following format: [(1,1),(2,1)], 'add', 11 [(1,2),(1,3)], 'div', 2 [(3,1),(4,1),(3,2),(4,2)], 'times', 240 [(2,2),(2,3)], 'minus', 3 ... Each line is a tuple I want to create. How is it possible to convert each string line into a tuple? For example, line string "[(1,1),(2,1)], 'add', 11" should be converted to a tuple: ([(1, 1), (2, 1)], 'add', 11) . So far, I tried: tuples = [] for line in file: tuples.append((line,)) But I am getting a string conversion [("[(1

Python: Using lower function on tuples

这一生的挚爱 提交于 2019-12-06 08:08:18
I'm new to Python and have looked at quite a bit of documentation to figure out what is going on, but haven't had any luck. I have a list of tuples that I need to convert to lowercase and perform mathematical operations on all values in the list. The "E", needs to become an "e" in order to perform mathematical operations. If there is a single value in a given list of tuples, the following works: EarthU = ['1.3719107E+11', '8.3311764E-02', '2.2719107E+11', '1.4880643E+03'] earthU = [element.lower() for element in EarthU] earthU = [(0.3048*0.3048)*float(element) for element in earthU] If there