-5

So basically I have this code:

try:
    fhanddate = open('AAPLprice.txt')

except:
    print 'Could not open file - closing application'
    exit()

stock_date = []

for line in fhanddate:
    p = line.strip()
    q = p.split(',')
    r = q[0:]

    stock_date.append(r)

for line in stock_date:
    pass
last = line
print last[0]

try:
    fhanda = open('AAPLprice.txt')
except:
    print 'Could not open file - closing application'
    exit()

stock_priceA = []

for line in fhanda:
    p = line.strip()
    q = p.split(',')
    r = q[-1:]
    stock_priceA.append(r)

print max(stock_priceA)

My output as a result is :

2015-07-21    
['129.606052']

So I want to know how I can combine both of these outputs so I get : 2015-07-21 129.606052 , as a result

When I try to just combine them I get the "TypeError: cannot concatenate 'str' and 'list' objects" error

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
coderific
  • 33
  • 1
  • 9

1 Answers1

0

You could simply join them together with a "+":

a = 2015-07-21 
b = ['129.606052']
print a + b[0]

b[0] takes the first item in the list, b. In this case, it takes out the only item in the list. You can add a space by simply adding a string in between them:

print a + " " + b[0]
Anthony Pham
  • 3,096
  • 5
  • 29
  • 38