Skip to main content

All Questions

Tagged with
0 votes
1 answer
39 views

updating dictionaries in python from list of booleans

I have an empty dictionary I want to add to. My solution works but I want to keep adding for each iteration in a dataset. The outcome is only showing one key:value pair. Is there a way to do this? My ...
n3wb's user avatar
  • 7
0 votes
2 answers
404 views

append() is overwriting the previous data he has written instead of just adding at the end

i'm wondering why the function append() is overwritting the elements given in a list that he has to write one after another. I'm really lost here. So here is the list of elements (I use fake identity ...
Matteo's user avatar
  • 23
0 votes
1 answer
54 views

How to append to a list the current -and not the final after iteration- state of another list? [duplicate]

Here is a simplified version of my code(I use for-loops with a single iteration just to "simulate" normal loops that I have in the original code): import numpy as np b=[] for i in range(1): ...
Makis Karasavvidis's user avatar
0 votes
1 answer
303 views

Adding next element in list if previous already added

I would like to append the next element from a list, if present in another list, from a certain element on and so on. I' ll explain further: I have these 2 lists numb_5 = [1, 2, 3, 4, 5] numb = [3, 1, ...
luca giovanni voglino's user avatar
1 vote
2 answers
422 views

How to extract and append the list(as dict values) from python dictionary to a list having an list of dictionary?

Here z is a list of dict(). z = [{'loss': [1, 2, 2] , 'val_loss':[2,4,5], 'accuracy':[3,8,9], 'val_accuracy':[5,9,7]}, {'loss': [1, 2, 2] , 'val_loss':[2,4,5], 'accuracy':[3,8,9], 'val_accuracy':[...
manoj kaushik's user avatar
0 votes
2 answers
122 views

Using .append to iterate upon an expanding list of numbers in Python

Both these methods return a None type; their purpose is to append a new number equal to 1 higher than the final integer in the list. The dual print statements are just to test the viability of the ...
Arian Ghorbani's user avatar
0 votes
2 answers
54 views

Python: How to iterate over a list of dictionaries and add each dictionary as value to a new dictionary with a unique key - no repeats

Have a list of dicts. I want to add a key to each dict and append them all to one dict. How do i do this without getting repeats of the same entry into new dict? I tried this code: # a_list is a ...
suspense_hey's user avatar
4 votes
7 answers
475 views

How to combine every 5 lists inside of a list in python?

I have a large list of lists, for example: list = [['a'], ['b'], ['c'], ['1234'], ['d'], ['e'], ['g'], ['h'], ['i'], ['56']] I would like to combine every 5 lists into one list of elements and so on. ...
Swathika's user avatar
-2 votes
2 answers
302 views

List append in a "for" loop

I am trying to get a list of elements using a for loop to index my previous list. Here's the code: for index in range(1,810): list.extend(t[index]) list.extend(t[index+1]) list.extend(t[...
r4diohead's user avatar
-2 votes
3 answers
4k views

appending to empty lists through a for loop but my lists print out empty

I've written a function whose purpose is to open, read, access data values within the each file in an indicated directory and iteratively append each files data entries into empty lists which will ...
Jean-Paul Ventura's user avatar
1 vote
6 answers
3k views

How do I square each item in a list using append?

start_list = [5, 3, 1, 2, 4] for i in start_list: start_list.append(i**2) I was under the assumption that value of each list item is assigned to i while the iteration happens. But given that the ...
ruben_KAI's user avatar
  • 325