Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!