tuples

How use system.tuple in powershell?

浪尽此生 提交于 2019-12-04 07:57:48
Just for curiosity, it's not a 'I must have it', but how declare a tuple using system.tuple class in powershell? I'm using powershell.exe.config to load framework 4.0 but I'm not able to create a tuple. Trying this: PS C:\ps1> $a = [System.Tuple``2]::Create( "pino", 34) Chiamata al metodo non riuscita. [System.Tuple`2] non contiene un metodo denominato 'Create'. In riga:1 car:31 + $a = [System.Tuple``2]::Create <<<< ( "pino", 34) + CategoryInfo : InvalidOperation: (Create:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound sorry for Italian sample... Thank you for help. EDIT:

How to remove quotes and the brackets within a tuple in python to format the data

人盡茶涼 提交于 2019-12-04 07:14:38
问题 I am trying to print only the maximum occurring character and its count. import collections s = raw_input() k = (collections.Counter(s).most_common(1)[0]) for lists, we have strip "".join method but how to deal with tuple the opposite way, i.e., removing the quotes and bracket. So, here is what I want the output to be without quotes and brackets input = "aaabucted" output = ('a', 3) I want the output to be a, 3 . 回答1: The quotes aren't in the data, they are just added when displaying the

How can i sort a list of tuples by one of it's values and then the other? [duplicate]

谁说我不能喝 提交于 2019-12-04 07:00:54
问题 This question already has answers here : Sorting a Python list by two fields (7 answers) Closed 2 years ago . I'll get to the point,i have this: ocurrencias = [('quiero', 1), ('aprender', 1), ('a', 1), ('programar', 1), ('en', 1), ('invierno', 2), ('hace', 1), ('frio', 1), ('este', 1)] I want to sort it by the second value of the tuples and then by their string value and then print every element to get this: output:invierno 2 a 1 aprender 1 en 1 este 1 frio 1 hace 1 programar 1 quiero 1 Don't

Get Tuple from a collection by one of its values?

让人想犯罪 __ 提交于 2019-12-04 07:00:00
问题 Is there a way to get a Tuple from a collection by only one of the Tuple's values? For example when I use this Tuple struct: public struct Tuple<T1, T2> { public readonly T1 Item1; public readonly T2 Item2; public Tuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2;} } Is there a way to get all Tuples that have a specific item (Item1 or Item2). I thought about some kind of HashMap since looping through a list of tuples and checking each tuple for a match is quite inefficient for large

swap temporary tuples of references

醉酒当歌 提交于 2019-12-04 06:56:23
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 test { public: test() :v1(10), v2(10) {} class iterator { public: iterator(std::vector<int>& _v1, std:

Why can't I subclass tuple in python3?

此生再无相见时 提交于 2019-12-04 05:51:00
Let's preface this question by saying that you should use __new__ instead of __init__ for subclassing immutable objects . With that being said, let's see the following code: class MyTuple(tuple): def __init__(self, *args): super(MyTuple, self).__init__(*args) mytuple = MyTuple([1,2,3]) This works in python2, but in python3 I get: Traceback (most recent call last): File "tmp.py", line 5, in <module> mytuple = MyTuple([1,2,3]) File "tmp.py", line 3, in __init__ super(MyTuple, self).__init__(*args) TypeError: object.__init__() takes no parameters Why does this happen? What changed in python3?

Tuple to List - Python / PostgreSQL return type of SETOF Record

久未见 提交于 2019-12-04 05:20:01
问题 so from this code: from dosql import * import cgi import simplejson as json def index(req, userID): userID = cgi.escape(userID) get = doSql() rec = get.execqry("select get_progressrecord('" + userID + "');", False) return json.dumps(rec) Notice that the variable rec, receives a query from the database, from this defined function I created in PostgreSQL: create or replace function get_progressrecord(in int, out decimal(5,2), out decimal(5,2), out decimal(4,2), out text, out int, out decimal(4

Test assertions for tuples with floats

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 05:16:40
I have a function that returns a tuple that, among others, contains a float value. Usually I use assertAlmostEquals to compare those, but this does not work with tuples. Also, the tuple contains other data-types as well. Currently I am asserting every element of the tuple individually, but that gets too much for a list of such tuples. Is there any good way to write assertions for such cases? Consider this function: def f(a): return [(1.0/x, x * 2) for x in a] Now I want to write a test for it: def testF(self): self.assertEqual(f(range(1,3)), [(1.0, 2), (0.5, 4)]) This will fail because the

Python: How to write a dictionary of tuple values to a csv file?

与世无争的帅哥 提交于 2019-12-04 04:44:21
问题 How do I print the following dictionary into a csv file? maxDict = {'test1': ('alpha', 2), 'test2': ('gamma', 2)} So, that the output CSV looks as follows: test1, alpha, 2 test2, gamma, 2 回答1: import csv with open("data.csv", "wb") as f: csv.writer(f).writerows((k,) + v for k, v in maxDict.iteritems()) 回答2: maxDict = {'test1': ('alpha', 2), 'test2': ('gamma', 2)} csvData = [] for col1, (col2, col3) in maxDict.iteritems(): csvData.append("%s, %s, %s" % (col1, col2, col3)) f = open('test.csv',

Python `dict` indexed by tuple: Getting a slice of the pie

江枫思渺然 提交于 2019-12-04 04:39:55
问题 Let's say I have my_dict = { ("airport", "London"): "Heathrow", ("airport", "Tokyo"): "Narita", ("hipsters", "London"): "Soho" } What is an efficient (no scanning of all keys), yet elegant way to get all airports out of this dictionary, i.e. expected output ["Heathrow", "Narita"] . In databases that can index by tuples, it's usually possible to do something like airports = my_dict.get(("airport",*)) (but usually only with the 'stars' sitting at the rightmost places in the tuple since the