string - Python merge items from two list -


i have following codes:

    j in range(4):       print md_array[j:j+1]     j in range(4):         print y_array[j:j+1]     j in range(4):       print md_array[j:j+1]+y_array[j:j+1]     j in range(4):       print "%s%s" % (md_array[j:j+1], y_array[j:j+1]) 

the results are:

['12/1/']['12/2/']['12/3/']['12/34/'] ['2011']['2010']['2009']['2008'] ['12/1/', '2011']['12/2/', '2010']['12/3/', '2009']['12/34/', '2008'] ['12/1/']['2011']['12/2/']['2010']['12/3/']['2009']['12/34/']['2008'] 

but want output

    ['12/1/2011']['12/2/2010']['12/3/2009']['12/34/2008'] 

i tried append failed...so what's wrong codes??

array[start_index:end_index] gives slice, sub-list of list it's applied on. in case, want single item. try following code:

for j in range(4):     print "%s%s" % (md_array[j], y_array[j]) 

you can read more slicing , indexes on documentation lists.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -