I've got a big list of training_data with 50,000 samples. Every sample contains two sublists which contain two elements (sample, label).
I accidentally created another list inside the label item which has again two items.
ie)
main_list
_______|_______
| |
sample label(list)
_____|_____
a(list) b(list)
I want to remove 'b' sub-list from every example (50000). I hope I did explain it correctly. Save me.
If I understand correctly, try new_list = [ [x[0], x[1][0]] for x in main_list]
. In any way, list comprehension will probably be enough to fix your problem...
I've tried to recreate your list hierarchy as follows:
a = ["w", "x"]
b = ["y", "z"]
label = [a, b]
sample = ["sample1", "sample2"]
main_list = [sample, label]
This gives us that
print(main_list)
[['sample1', 'sample2'], [['w', 'x'], [ 'y', 'z']]]
Then to remove b
, you simply have to set
main_list = [main_list[0], main_list[1][0]]
Does this achieve what you want?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.