tuples

converting string to tuple in erlang .any pointer?

烈酒焚心 提交于 2019-12-24 14:06:02
问题 how to convert string to tuple in erlang? f.e A="{"hi","how"}" and i want it to converted into B={"hi","how"}. when i call function list_to_tuple(A) it gives output as:-{123,60,60,34,106,105,100,34,62,62,44,34,104,105,34,125} rather than {"hi","how"} 回答1: You should use erl_scan module to tokenize the string and erl_parse to convert the tokens to a erlang term. % Note the '.' at the end of the expression inside string. % The string has to be a valid expression terminated by a '.'. 1> Str = "{

Learn Python The Hard Way - Exercise 39

非 Y 不嫁゛ 提交于 2019-12-24 13:26:22
问题 On Exercise 39 of Learn Python The Hard Way, lines 37 to 39 look like this: print "-"*10 for state, abbrev in states.items(): print "%s has the city %s" % (state, abbrev) I thought I understood this. I thought Python was taking the KEY:VALUE from "states" and assigning the KEY to "state" and the VALUE to "abbrev". However, I found something strange happened when I entered the following code: print "-"*10 for test in states.items(): print "%s has the city %s" % (test) It produces the same

How do I ignore brackets when loading exteral table in HIVE

怎甘沉沦 提交于 2019-12-24 13:09:26
问题 I'm trying to load an extract of a pig script as an external table in HIVE. Pig enclosed each row between brackets () (tuples?) like this: (1,2,3,a) (2,4,5,b) (4,2,6,c) and I can't find a way to tell HIVE to ignore those brackets which results in null values for the first column as it is actually an integer. Any thoughts on how to proceed? I know I can use a FLATTEN command in PIG but I would also like to learn how to deal with these files directly from HIVE. 回答1: There is no way to do this

Why don't tuples get the same ID when assigned the same values?

纵然是瞬间 提交于 2019-12-24 10:35:38
问题 When I executed the following steps, both tuples ( a and b ) haven't retained their original IDs even when I reassigned older values ( (1,2) ). >>> a , b = (1,2) , (1,2) >>> a (1, 2) >>> b (1, 2) >>> id(a) , id(b) (80131912, 91541064) >>> a , b = (3,4) , (3,4) >>> a (3, 4) >>> b (3, 4) >>> id(a) , id(b) (91559048, 91689032) >>> a , b = (1,2) , (1,2) >>> a (1, 2) >>> b (1, 2) >>> id(a) , id(b) (91556616, 91550408) But in the following case, both have gotten their older IDs back. >>> a = (1,2)

Haskell: how to compare tuples?

北城余情 提交于 2019-12-24 10:00:18
问题 I'm trying to make a tuple list store some information in a particular way. Such as scotland belongs to uk , england belongs to uk , etc. Then take two strings as arguments ( String -> String -> Bool ) to make something like: Main> owns "china" "beijing" True Main> owns "uk" "beijing" False Here's my code: lst = [("uk","scotland"),("uk","england"),("uk","wales"),("china","beijing"),("china","hongkong"),("china","shanghai")] owns :: String -> String -> Bool owns a b = [n|(a,b) <- lst, (n == a)

sorting a list of tuples

萝らか妹 提交于 2019-12-24 09:58:06
问题 I have a list of tuples of the form (a,b,c,d) and I want to copy only those tuples with unique values of 'a' to a new list. I'm very new to python. Current idea that isn't working: for (x) in list: a,b,c,d=(x) if list.count(a)==1: newlist.append(x) 回答1: If you don't want to add any of the tuples that have duplicate a values (as opposed to adding the first occurrence of a given a , but none of the later ones): seen = {} for x in your_list: a,b,c,d = x seen.setdefault(a, []).append(x) newlist =

Compare Tuples and find next index in it's same position in python

落爺英雄遲暮 提交于 2019-12-24 08:39:17
问题 R=[(1,10,14,34),(2,5,19,21),(3,7,31,32),(1,9,12,31),(2,10,11‌​,22),(4,8,14,32),(13‌​,15,19,34),(1,5,15,2‌​0),(3,26,19,25),(4,1‌​7,19,21),(4,1‌​7,20,21)] For each tuple in R, find the next index of each elements with the same element position where other elements should not be present in both tuples. FOR Index 0 and 1 here is expected sample results 0: 4,5,6,7 1: 2,5,6,8 . . . . . so on Here is my code is going too detail and too lengthy and taking too long to run for my actual project. so i

Finding tuples with a common element

我的梦境 提交于 2019-12-24 07:44:30
问题 Suppose I have a set of tuples with people's names. I want to find everyone who shares the same last name, excluding people who don't share their last name with anyone else: # input names = set([('John', 'Lee'), ('Mary', 'Miller'), ('Paul', 'Ryan'), ('Bob', 'Ryan'), ('Tina', 'Lee'), ('Bob', 'Smith')]) # expected output {'Lee': ['Tina', 'John'], 'Ryan': ['Bob', 'Paul']} # or similar This is what I am using def find_family(names): result = {} try: while True: name = names.pop() if name[1] in

do record_info and tuple_to_list return the same key order in Erlang?

妖精的绣舞 提交于 2019-12-24 07:29:09
问题 I.e, if I have a record -record(one, {frag, left}). Is record_info(fields, one) going to always return [frag, left] ? Is tl(tuple_to_list(#one{frag = "Frag", left = "Left"})) always gonna be ["Frag", "Left"] ? Is this an implementation detail? Thanks a lot! 回答1: The short answer is: yes, as of this writing it will work. The better answer is: it may not work that way in the future, and the nature of the question concerns me. It's safe to use record_info/2 , although relying on the order may be

How to create tuples from a single list with alpha-numeric chacters?

南楼画角 提交于 2019-12-24 07:19:35
问题 I have the following list with 2 elements: ['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2'] I need to make a list or zip file such that each alphabet corresponds to its number further in the list. For example in list[0] the list/zip should read {"A":"6", "G":"6", "C":"35","T":"25","T":"10"} Can I make a list of such lists/zips that stores the corresponding vales for list[0], list[1],...list[n]? Note: The alphabets can only be A,G,C or T, and the numbers can take anyvalue Edit 1: Previously, I