Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For Python 2.7 For the quicksplit.py script modify the script to print to the user all the keys and let the user select which key

For Python 2.7

  1. For the quicksplit.py script modify the script to print to the user all the keys and let the user select which key to print values for via raw_input function.

#! /usr/bin/env python # -*- coding: utf-8 -*-

'''split file and create a list ''' FileName = "datasplit.txt"

Reader = open(FileName, 'rU')

Delim = '\t'

ValueList = [] ValueDict = {}

for Line in Reader: AllVals = Line.split(Delim) x,y = AllVals[:2] # Make a Dictionary ValueDict[x] = float(y) # Also a List ValueList.append( [x, float(y) ] )

Reader.close()

# print out the values of ValueDict for each key # in QueryList, # hint: remember two ways to retrieve from a dictionary

# Note start with something that works and then move on. QueryList = ['HK','MP','QT','WZ']

# print ValueDict

# fast way for Query in QueryList: print Query, '==>', ValueDict.get(Query,'not found')

# slower way KeyList = ValueDict.keys() for Query in QueryList: if Query in KeyList: print Query, '==>', ValueDict[Query] else: print Query,'not found'

# print "KEYS ==>",ValueDict.keys() # print ValueList

-----------------------------------

datasplit.txt

AD 0 c BE 1 d CF 4 e DG 9 f EH 16 g FI 25 h GJ 36 i HK 49 j IL 64 k JM 81 l KN 100 m LO 121 n MP 144 o NQ 169 p OR 196 q PS 225 r QT 256 s RU 289 t SV 324 u TW 361 v UX 400 w VY 441 x WZ 484 y

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions