tuples

Remove duplicate tuples from a list if they are exactly the same including order of items

半城伤御伤魂 提交于 2021-02-05 20:26:14
问题 I know questions similar to this have been asked many, many times on Stack Overflow, but I need to remove duplicate tuples from a list, but not just if their elements match up, their elements have to be in the same order. In other words, (4,3,5) and (3,4,5) would both be present in the output, while if there were both (3,3,5) and (3,3,5) , only one would be in the output. Specifically, my code is: import itertools x = [1,1,1,2,2,2,3,3,3,4,4,5] y = [] for x in itertools.combinations(x,3): y

Remove duplicate tuples from a list if they are exactly the same including order of items

匆匆过客 提交于 2021-02-05 20:24:00
问题 I know questions similar to this have been asked many, many times on Stack Overflow, but I need to remove duplicate tuples from a list, but not just if their elements match up, their elements have to be in the same order. In other words, (4,3,5) and (3,4,5) would both be present in the output, while if there were both (3,3,5) and (3,3,5) , only one would be in the output. Specifically, my code is: import itertools x = [1,1,1,2,2,2,3,3,3,4,4,5] y = [] for x in itertools.combinations(x,3): y

Return more than one value in python function

社会主义新天地 提交于 2021-02-05 12:31:07
问题 I was trying to use *args with a for loop in python, however I don't see how to return all the values passed to the function, which should return all the even numbers def f_even(*args): for item in args: if item%2 == 0: return item The above code returns only the first value, as I guess after the return it goes out of the function. Indeed, if I use print instead, it works I'm trying to find a way to return a tuple with all the even numbers when I pass let's say (1,2,3,4,5) to the function

Typescript inferring Tuple as Array Incorrectly

混江龙づ霸主 提交于 2021-02-05 12:08:55
问题 Apologize for my English first. I have a function like function func(): [string, string[]] which returns a Tuple. However, when I implement the return statement like var test = ['text', ['foo', 'bar']]; return test; Typescript inferred my return type as (string | string[])[] instead of [string, string[]] . Did I missed something or should I need to cast the return object as Tuple explicitly everytime like return <[string, string[]]>['text', ['foo', 'bar']] . If yes then isn't it quite

Typescript inferring Tuple as Array Incorrectly

时光怂恿深爱的人放手 提交于 2021-02-05 12:06:04
问题 Apologize for my English first. I have a function like function func(): [string, string[]] which returns a Tuple. However, when I implement the return statement like var test = ['text', ['foo', 'bar']]; return test; Typescript inferred my return type as (string | string[])[] instead of [string, string[]] . Did I missed something or should I need to cast the return object as Tuple explicitly everytime like return <[string, string[]]>['text', ['foo', 'bar']] . If yes then isn't it quite

TypeError: can only concatenate tuple (not “int”) to tuple

余生长醉 提交于 2021-02-05 11:37:25
问题 i am trying to return a value from db and getting this error.I tried the previously answered questions here,but no luck.Can anyone help me? @frappe.whitelist() def generate_barcode(): last_barcode = frappe.db.sql("""\ select MAX(barcode) from `tabItem` """) if last_barcode: last_barcode = last_barcode + 1 else: x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] random.shuffle(x) last_barcode = x[0] return {'last_barcode':last_barcode} adding traceback: Traceback (innermost last): File "/home/adminuser/frappe

Safe unpack empty tuple array

旧街凉风 提交于 2021-02-05 11:21:25
问题 The line import re; print(re.findall("(.*) (.*)", "john smith")) outputs [("john", "smith")] , which can be unpacked like [(first_name, last_name)] = re.findall(...) . However, in the event of a non-match ( findall returning [] ) this unpacking throws ValueError: not enough values to unpack (expected 1, got 0) . What is the correct way to safely unpack this array of tuples, which would work in both match ( [("john", "smith")] ) and non-match ( [] ) scenarios? 回答1: The generic answer is to

Safe unpack empty tuple array

依然范特西╮ 提交于 2021-02-05 11:21:12
问题 The line import re; print(re.findall("(.*) (.*)", "john smith")) outputs [("john", "smith")] , which can be unpacked like [(first_name, last_name)] = re.findall(...) . However, in the event of a non-match ( findall returning [] ) this unpacking throws ValueError: not enough values to unpack (expected 1, got 0) . What is the correct way to safely unpack this array of tuples, which would work in both match ( [("john", "smith")] ) and non-match ( [] ) scenarios? 回答1: The generic answer is to

Is there a shorthand way to convert a Tuple to a ValueTuple?

对着背影说爱祢 提交于 2021-02-05 07:56:07
问题 I have just included a DLL file into my project and am using a method which returns a List<Tuple> . I have only recently became aware of the ValueTuple datatype in C# 7 and want to use it instead of the normal Tuples which are returned. I am aware that I could loop through and do the conversion manually however I would like to avoid doing this if possible and was wondering if anyone was aware of a shorthand way to casting a Tuple to a ValueTuple? If I am being ignorant and this isn't possible

structured binding of member variables

纵饮孤独 提交于 2021-02-05 07:52:16
问题 In visual studio 2017, after turning on /std:c++17 , I can do auto [d1, d2] = func_return_tuple(); , where func_return_tuple() returns a tuple of two double value. However, if class A has two member variable d1_ and d2_ , I can't do A a; auto [a.d1_, a.d2_] = func_return_tuple(); Is there a way out? Of course, std::tie(a.d1_, a.d2_) = func_return_tuple(); always works. 回答1: Is there a way out? Basically, no. Structured bindings is only about decomposing an object into constituent elements. It