[Tutor] Extract Field from List

Dennis Lee Bieber wlfraed at ix.netcom.com
Sun Aug 8 13:08:46 EDT 2021


On Sun, 08 Aug 2021 12:59:25 -0400, Dennis Lee Bieber
<wlfraed at ix.netcom.com> declaimed the following:


	If you want to access using the "name" you initially read, change the
outer "data" from a list to a dictionary...

>
>data = []	#main results list
data = {}
>for name in <whatever you call it after using tab separation>:
>	data_i = []	#result list for one "ligand"/name
>	for i in range(1,11):
>		full_name = "%s.%s.log" % (name, i)		#create file name
>		data_i.append(np.genfromtxt(full_name, 
>						skip_header=28, skip_footer=1)
>				#fetch contents of said file, append to result list
>	data.append(data_i)	#append "name" results list to main results
	data[name] = data_i

>
>	To access the data for, say, name-2, and file 3, you would use
>
>		data[1][2]	#Python lists start at 0, not one, so you have to
>					#adjust the indices used.

		data["name-2"][2]



-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list