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
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started