Find partial tuple in list of tuple

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

Haskell, tuple (double, string) [closed]

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

Spanning repeatable keys

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