How to print the keys of a list with using strings ?
How to print the keys of a list with using strings ?
I want to see all the keys of these lists, yet I am having trouble printing them. Would be great if you can correct my way of thinking.
Best Regards,
Deniz
batch_meta = all_data[0]
data_batch1 = all_data[1]
data_batch2 = all_data[2]
data_batch3 = all_data[3]
data_batch4 = all_data[4]
data_batch5 = all_data[5]
test_batch = all_data[6]
#print(batch_meta)
#print(data_batch1.keys())
for i in range(1,7) :
y = str(i)
x = str('data_batch')
z = dict(x+y)
z.keys()
Hello Newbie, yes,of course. When I print data_batch1.keys() alone I see this, but I want to be able to see all the data_batch..'s . That's why I tried to put it in a for loop. (output is below). For input I don't actually know what can I provide you. Out[8]:you dict_keys([b'filenames', b'data', b'batch_label', b'labels']) .
– Deniz yıldırım
Aug 27 at 20:33
1 Answer
1
You shouldn't try to manipulate strings to get the names of objects. Why not loop over all_data
directly? You can even loop over a slice of all_data
if you don't want all of it
all_data
all_data
for batch in all_data[1:6]:
print(batch.keys())
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Hello Deniz, could you provide an example with an input and the expected output?
– abc
Aug 27 at 20:15