Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture is to be made.
SOLUTION
f = open("file.txt", "r")
d={}
temp=0
for x in f:
#if the line is [END DESCRIPTION] or [END
ACTION] then don't store it.
if len(x)==18 or
len(x)==13:
temp=0
#if the value of temp is 1 , we've encountered
[END DESCRIPTION] start storing
if temp==1:
#store the next lines
and remove the railing new lines
d[val].append([x.strip()])
#if the value if temp is 2 , we've encountered
[END ACTION] start storing again
elif temp==2:
#stripping the trailing
white spaces and new line characters
x=x.strip()
#find the location of '
, 2.1 ' and store it in t
t=x.find(",
"+str(int(val))+".")
#if the dictionary has
only 1 list by the key add one more for [START ACTION] lines
if len(d[val])==1:
#Adding another list
d[val].append([])
#Adding lines after
[START ACTION] in a tuple and using the position of ' , 2.1' in
t
d[val][1].append((x[:t],float(x[t+2:])))
try:
#Check if the line have
number then convert it to float
val=float(x)
#Form the number as a
key to an empty list
d[val]=[]
except ValueError:
#if the line above doesn't have a number it'll
encounter this part
#assign 1 if line is
[START DESCRIPTION] whose length is 20, 2 if line is [START ACTION]
whose length is 15and 0 otherwise
if len(x)==20:
temp=1
elif len(x)==15:
temp=2
print(d)
HOPE THIS HELPS IF YOU LIKE THE SOLUTION PLEASE RATE IT.
THANKS!
Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture...
Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...
I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...