Category : dictionary

I’m trying to finish writing an algorithm for a class. I’m trying to create a list, value, in which each element is the summation of two other numbers. Here’s the line that is giving me trouble: value = [Q_hat_cluster[cluster][i] + U_hat_cluster[cluster][i] for i in range(5)] I keep getting IndexError: invalid index to scalar variable errors. ..

Read more

Consider the following nested dictionary: {year: {region: {country: ((val1, val2), (val3, val4))}}} {2015: {‘Europe’: {‘Switzerland’: ((1.0, 7.6), (0.419, 2.318))}, {‘Iceland’: ((1.2, 3.2), (2.3, 1.00))}} I need to write a function that taskes as input the country name string, and this nested dictionary, and prints/returns values based on said country name. My main question is how ..

Read more

I am giving the full code so you can see the concept ( I am a new learner in python) import uuid # GET A RANDOM ID FOR THE CUSTOMER from datetime import date # GET CURRENT DATE TodayDate = date.today() Dates = {} Customers = {} FirstEmployeeAccountUsername = "coffee1" FirstEmployeeAccountPassword = "coffeeshop1" SecondEmployeeAccountUsername = ..

Read more

I want to add my excel file in python dictionary by making Id as the key of the dictionary and rest of the row it’s value. The program I wrote is import pandas as pd dict_Amazon_small ={} sample_data = pd.read_csv(r’Amazon_small.csv’, encoding=’cp1252′) for row in sample_data: dict_Amazon_small[row[0]] = row[1] + row[2] + row[3] + row[4] This ..

Read more

Consider the following .csv: country: region: rank1: rank2: rank3: switzerland West Europe 1 7.25 0.04 Iceland West Europe 2 7.04 1.03 Canada North America 3 7.32 0.03 I need to create a dictionary in the following structure, with one big dictionary containing dictionaries for each region containing another dictionary for countries, with tuples for the ..

Read more

import random #NumSubjects = int(input("Enter how many subjects you have here")) NumQ = int(input("Enter the number of questions you want to do here:")) #Asks how many questions then shuffles them randomQ = random.sample(range(0, 10), NumQ) #Question bank QuesBank = { 0:’A’, 1:’B’, 2:’C’, 3:’D’, 4:’E’, 5:’F’, 6:’H’, 7:’I’, 8:’J’, 9:’K’, 10:’L’ } #”Place holding questions ..

Read more