tuples

Write list of tuples to txt file

半世苍凉 提交于 2019-12-24 03:12:50
问题 Consider this list of tuples: list=[((0.0, 0.0), (0.00249999994412065, -509.707885742188), (0.00499999988824129, -1017.52648925781), (0.0087500000372529, -1778.51281738281), (0.0143750002607703, -2918.21899414063), (0.0228125005960464, -4609.91650390625))] I'd like to write the information to a txt file in this format: 0.0 0.0 0.00249999994412065 -509.707885742188 .... I've been using this code: with open(fname, 'w') as graphd: for row in list: print >>graphd, ', '.join(map(str, row)) graphd

OCaml Stack of tuples

放肆的年华 提交于 2019-12-24 02:23:28
问题 I am trying to create a stack of tuples in OCaml using the following piece of code let (k : (string*string) Stack.t) = Stack.create ;; But when doing so i get an error while compiling telling Error: This expression has type unit -> 'a Stack.t but an expression was expected of type (string * string) Stack.t Am pretty new to OCaml. Can someone point out where I am going wrong? 回答1: Stack.create is a function which takes the value () (of type unit ) and give you back a stack. So you should do:

OCaml Stack of tuples

女生的网名这么多〃 提交于 2019-12-24 02:23:05
问题 I am trying to create a stack of tuples in OCaml using the following piece of code let (k : (string*string) Stack.t) = Stack.create ;; But when doing so i get an error while compiling telling Error: This expression has type unit -> 'a Stack.t but an expression was expected of type (string * string) Stack.t Am pretty new to OCaml. Can someone point out where I am going wrong? 回答1: Stack.create is a function which takes the value () (of type unit ) and give you back a stack. So you should do:

Idris - map function on custom dependent data type fails

放肆的年华 提交于 2019-12-24 01:47:07
问题 I am relatively new to idris and dependent-types and I encountered the following problem - I created a custom data type similar to vectors: infixr 1 ::: data TupleVect : Nat -> Nat -> Type -> Type where Empty : TupleVect Z Z a (:::) : (Vect o a, Vect p a) -> TupleVect n m a -> TupleVect (n+o) (m+p) a exampleTupleVect : TupleVect 5 4 Int exampleTupleVect = ([1,2], [1]) ::: ([3,4],[2,3]) ::: ([5], [4]) ::: Empty It is inductively constructed by adding tuples of vectors and indexed by the sum of

Haskell: Combine integers in a list of tuples [duplicate]

半城伤御伤魂 提交于 2019-12-24 01:11:49
问题 This question already has answers here : How to group similar items in a list using Haskell? (5 answers) Closed 4 years ago . I need to get from here: [(2,"a"), (1,"a"), (1,"b"), (1,"c"), (2,"dd")] to here: [([1, 2], "a"), ([1], "b"), ([1], "c"), ([2], "dd")] So far I have combineInts listTuple = someFunc (map (\(num, str) -> ([num], str)) listTuple) where "someFunc" is the bit I still need to figure out and implement. I believe it should utilize foldr, map, and/or intercalate to accomplish

comparing two dictionaries with list type values

北战南征 提交于 2019-12-23 22:52:51
问题 I'm trying to compare two dictionaries. My approach is to turn them into two separate lists of tuples and to then use the set module. Here is an illustration: dict = {'red':[1,2,3],'blue':[2,3,4],'green':[3,4,5]} dict1 = {'green':[3,4,5],'yellow':[2,3,4],'red':[5,2,6]} intersection = set(set(dict.items()) & set(dict1.items())) apparently, this is comparing two lists of tuples and python doesn't like that. I get a TypeError: 'list' is unhashable error (or similar wording). I would like

How to scatter plot one x data versus several unequal y data plots in matplotlib.pyplot

▼魔方 西西 提交于 2019-12-23 22:26:54
问题 Basically I have x versus y tuple of different length. How can I plot the following in matplotlib? x=[1,2,3,4] y=([1,1.1,1.4,0.9,0.8],[2.1,2.2,2.3],[3.1,3.3],[4.4,4.5,4.3,4.22,4.2,4.1,4.4411]) plt.scatter(x,y) Thank you 回答1: IIUC you need to expand your x list to y dimension and then flat obtained list and put in plt.scatter : x=[1,2,3,4] y=([1,1.1,1.4,0.9,0.8],[2.1,2.2,2.3],[3.1,3.3],[4.4,4.5,4.3,4.22,4.2,4.1,4.4411]) w = [[x[i]] * len(y[i]) for i in range(len(y))] In [555]: w Out[555]: [[1,

Create heatmap in python matplotlib with x and y labels from dict with {tuple:float} format

江枫思渺然 提交于 2019-12-23 22:00:42
问题 I have a dict that consists of movie-title pairs as keys and a similarity score as values: {('Source Code ', 'Hobo with a Shotgun '): 1.0, ('Adjustment Bureau, The ', 'Just Go with It '): 1.0, ('Limitless ', 'Arthur '): 1.0, ('Adjustment Bureau, The ', 'Kung Fu Panda 2 '): 1.0, ('Rise of the Planet of the Apes ', 'Scream 4 '): 1.0, ('Source Code ', 'Take Me Home Tonight '): 1.0, ('Midnight in Paris ', 'Take Me Home Tonight '): 1.0, ('Harry Potter and the Deathly Hallows: Part 2 ', 'Pina '): 1

max second element in tuples python [duplicate]

我的梦境 提交于 2019-12-23 21:00:35
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Sorting or Finding Max Value by the second element in a nested list. Python I've written a program that gives me a list of tuples. I need to grab the tuple with with the max number in the second value. (840, 32), (841, 3), (842, 4), (843, 4), (844, 6), (845, 6), (846, 12), (847, 6), (848, 10), (849, 4), ..snip... I need to get back (840,32) because 32 is the highest second number in the tuple. How can I achieve

Sorting tuples in python based on their values [duplicate]

做~自己de王妃 提交于 2019-12-23 18:41:35
问题 This question already has answers here : How to sort (list/tuple) of lists/tuples by the element at a given index? (10 answers) How to find most common elements of a list? (10 answers) Closed 5 years ago . I am trying to print the top 10 frequent words using the following code. However, its not working. Any idea on how to fix it? def reducer_count_words(self, word, counts): # send all (num_occurrences, word) pairs to the same reducer. # num_occurrences is so we can easily use Python's max()