tuples

Frequency analysis issues with tuple error

拈花ヽ惹草 提交于 2020-01-06 15:51:28
问题 In the match_letters function, with 'place = string.index(letter)' i keep recieving the same error of 'Value Error: tuple.index(x): x not a tuple.' Does anyone know how to solve this? It will be much appreciated :) Thanks def freq_analysis(): """ Summary: Perform a frequency analysis on a string Paramaters: text - The text to analyse Returns: A string containing the deciphered text """ text = input("enter text") letterCount = getLetterCount(text) Letter_Count_Tuple,new_letter_count,descending

Frequency analysis issues with tuple error

本秂侑毒 提交于 2020-01-06 15:51:11
问题 In the match_letters function, with 'place = string.index(letter)' i keep recieving the same error of 'Value Error: tuple.index(x): x not a tuple.' Does anyone know how to solve this? It will be much appreciated :) Thanks def freq_analysis(): """ Summary: Perform a frequency analysis on a string Paramaters: text - The text to analyse Returns: A string containing the deciphered text """ text = input("enter text") letterCount = getLetterCount(text) Letter_Count_Tuple,new_letter_count,descending

Why can't I search for a row in a pandas df using a date as part of a tuple index?

大兔子大兔子 提交于 2020-01-06 06:59:35
问题 I am trying to search a pandas df I made which has a tuple as an index. The first part of the tuple is a date and the second part is a forex pair. I've tried a few things but I can't seem to search using a date-formatted string as part of a tuple with .loc or .ix My df looks like this: Open Close (11-01-2018, AEDAUD) 0.3470 0.3448 (11-01-2018, AEDCAD) 0.3415 0.3408 (11-01-2018, AEDCHF) 0.2663 0.2656 (11-01-2018, AEDDKK) 1.6955 1.6838 (11-01-2018, AEDEUR) 0.2277 0.2261 Here is the complete

Extracting tuples from a list in Pandas Dataframe

大兔子大兔子 提交于 2020-01-06 04:59:44
问题 I have a dataframe with 12 column. I would like to extract the rows of a column depending on the values of another column. Sample of my dataframe order_id order_type order_items 45 Lunch [('Burger', 5), ('Fries', 6)] 12 Dinner [('Shrimp', 10), ('Fish&Chips', 7)] 44 Lunch [('Salad', 9), ('Steak', 9)] 23 Breakfast [('Coffee', 2), ('Eggs', 3)] I would like to extract the breakfast, lunch and dinner menu by extracting the first item of each tuple . and extract the number of orders from the next

How to iterate with range using itertools?

百般思念 提交于 2020-01-06 04:51:05
问题 Considering the following list within it 4 tuples: players_score = [ ('Joe', 100, 34, 38, 90, 67, 3, 10), ('Bob', 90, 38, 4, 100, 60, 4, 11), ('May', 80, 36, 40, 91, 70, 2, 12), ('Anna', 95, 32, 36, 92, 68, 8, 13) ] The players have been playing 7 games. In the first game, Joe has won with 100 points. I would like to score each player (of each game) according to the following: First/best player: 5 points Second player: 3 points Third player: 1 point Fourth player: -1 point -> But 0 points is

OCaml count consecutive elements in a list

。_饼干妹妹 提交于 2020-01-06 04:30:29
问题 I'm writing OCaml code that reads in a list and removes any char 'i's that appear at the beginning of the list. For instance, the list removeI['i';'i';'a';'c';'i'] should return -: int * char list = ['a';'c';'i'] , because there are 2 'i's at the beginning of the list. I believe I know how to implement this properly; however, I want to return a tuple that includes the number of removed 'i's as well as the new list with the 'i's removed. I know that may sound confusing, but an example would be

OCaml count consecutive elements in a list

倖福魔咒の 提交于 2020-01-06 04:30:27
问题 I'm writing OCaml code that reads in a list and removes any char 'i's that appear at the beginning of the list. For instance, the list removeI['i';'i';'a';'c';'i'] should return -: int * char list = ['a';'c';'i'] , because there are 2 'i's at the beginning of the list. I believe I know how to implement this properly; however, I want to return a tuple that includes the number of removed 'i's as well as the new list with the 'i's removed. I know that may sound confusing, but an example would be

Summing a tuple-of-tuples and a nested dict

扶醉桌前 提交于 2020-01-06 03:03:09
问题 I have data that can be represented in two different forms (for historical reasons that I won't go into). The first is a tuple of tuple s: t = (('a', 'x', 3), ('a', 'f', 1), ('b', 'r', 23), ('b', 'e', 3)) And the second as a dict of dict s: d = {'a' : {'x': 45, 'f' : 4}, 'b' : {'r' : 34, 'e' : 45}} Same data, different representation. I now need to end up with a combination of the two (and must maintain the tuple-of-tuples form rather than the nested dict form), with the values summed . i.e.

Why does matching on a tuple of dereferenced references not work while dereferencing non-tuples does?

百般思念 提交于 2020-01-05 07:44:20
问题 I'm trying to sort a Vec of enums. Please ignore the sorting mechanism itself, this is just a stripped-down example. use std::cmp::Ordering; enum MyEnum { Option1, Option2, } fn main() { let mut my_list: Vec<MyEnum> = vec![MyEnum::Option1, MyEnum::Option2, MyEnum::Option1]; // (1) - doesn't work my_list.sort_unstable_by(|a, b| match (*a, *b) { (MyEnum::Option1, MyEnum::Option1) => Ordering::Equal, (MyEnum::Option1, MyEnum::Option2) => Ordering::Less, _ => Ordering::Greater }); } I get the

How to convert a string of a list of tuples to a Python list of tuples [duplicate]

↘锁芯ラ 提交于 2020-01-05 02:31:49
问题 This question already has answers here : Converting a string of tuples to a list of tuples in Python (3 answers) Closed last year . I have a list of tuples saved into a string (unfortunately). I am looking for a fast an efficient way to convert this string to an actual list of tuples. Example: mylist_string = '[(40.7822603, -73.9525339), (40.7142, -74.0087), (40.7250027, -73.9413106), (40.703422, -73.9862948), (40.7169963, -74.0149991), (40.7420448, -73.9918131), (40.7287, -73.9799), (40