how to unpack a tuple in this form (‘abc’, [20, 20])? [closed]
Simply: a,b = ‘abc’, [20,20] If you removed the asterix, your code would have worked
Simply: a,b = ‘abc’, [20,20] If you removed the asterix, your code would have worked
i found: CalculPoids = p.Poids/(Enumerable.Repeat(10, p.Sum / 10).Concat(Enumerable.Repeat(p.Sum % 10, 1))).Count()
As @tobias_k suggested, the simplest way is to convert tuples and subtuples to string, and use the in operator for substring check: l = [(‘a’,’b’,’c’,’d’,’e’), (‘f’,’g’,’h’,’i’,’l’), (‘m’,’n’,’o’,’p’,’q’), (‘r’,’s’,’t’,’u’,’v’), (‘z’, ‘aa’, ‘ab’, ‘ac’, ‘ad’), …] def subtuple_index(tuples, t): def tuple2str(t): return ‘,{},’.format(‘,’.join(t)) t = tuple2str(t) for i,x in enumerate(map(tuple2str, tuples)): if t in x: return i … Read more
You can implement it using mapM_/traverse_ or the flipped argument versions: forM_/for_. I prefer for_ since it looks more like the “enhanced for-loop” from languages like Java. import Data.Foldable (for_) myPutStr :: [(Double,String)] -> IO () myPutStr vals = do for_ vals $ \(num, str) -> do putStr str putStr “: ” print (num * … Read more
First, you should be more specific of what you expect. If you want your list to be the sum of the numbers in the tuples, here’s what you can do: listnum = [sum(x) for x in listnum]
1> L_tup = [ 1> {“Caerus1”, “Ramses Refiner”}, 1> {“Caerus1”, “Jupiter Refiner”}, 1> {“Caerus1”, “Jupiter Other”}, 1> {“Caerus1”, “Trader 13”}, 1> {“Caerus1”, “Cathode Supplier 4”}, 1> {“Dionysus3”, “Cathode Supplier 4”}, 1> {“Dionysus3”, “Ramses Refiner”}, 1> {“Dionysus3”, “Trader 13”}, 1> {“Dionysus3”, “Jupiter Refiner”}, 1> {“Dionysus3”, “Jupiter Other”}, 1> {“Prometheus2”, “Jupiter Other”}, 1> {“Prometheus2”, “Ramses Refiner”}, 1> … Read more
Are you looking for this? var tupleList = new List<Tuple<string, string>>(); for (int i = 0; i < data.Count; i++) { for (int j = i + 1; j < data.Count; j++) { tupleList.Add(new Tuple<string, string>(data[i], data[j])); } }