All Questions
26 questions
4
votes
2
answers
3k
views
Skip multiple iterations in a loop
Looking for something that would allow skipping multiple for loops while also having current index available.
In pseudo code, is would look something like this:
z = [1,2,3,4,5,6,7,8]
for element in ...
2
votes
3
answers
97
views
python: get the last matching dictionary from list
How to get the last matching dictionary from list of dictionaries:
Example:
test_dict={'user'='xxx','tasks':[{'id':'01','age':'60'},{'id':'02','age':'50'},{'id':'01','age':'65'},{'id':'02','age':'65'...
0
votes
1
answer
202
views
Explicit type casting in python 2.7 list() function
Given first_list = []
What is the difference between
second_list = first_list
and
third_list = list(first_list) ?
I am having an error in a program in which appending the explicit casting (or ...
1
vote
3
answers
3k
views
Iterate over list and dict in parallel
I have a list that contains 5 variables, say:
list2=[1,2,3,4,5]
and I have a list of dict with 5 key-value pairs, which I initialized to be :
list1[i]= {"input1": 0, "input2": 0, "input3": 0, "...
0
votes
1
answer
27
views
Iterating through a list and passing each value to a function in Python
I have a list of IP addresses and I wish to use a Netmiko function to connect to each of these IP's in turn..
The function has IP as the first parameter, but I am not sure how to run through the ...
0
votes
1
answer
34
views
How to Change a Dictionaries Key Based on the Value Designated to the Same Key in Another Dictionary?
I am trying to update a dictionary key using key value pairs in another dictionary. The two dictionaries I am trying to combine are both nested into lists:
dictionary1 = [{ '32639': {'78549': {'526' :...
0
votes
1
answer
42
views
Not getting the iterations i want
I have been working on this for some time and I cant get the iterations I want from the loops I coded. The code starts by calling headerBody10() and appending the output to a list, dist. There are two ...
0
votes
2
answers
39
views
How to combine two lists together that are being formed while iterating another list?
I'm using scrapy to iteratively scrape some data, and the data is being output as two lists through each iteration. I want to combine the two lists into one list at each iteration, so that in the end ...
0
votes
0
answers
51
views
How can I get linear time complexity from this code?
The rest of this code is meant to search through any number of drives on our data analysis workstations and check that a particular file is not missing. This is of course just a piece of that code. ...
3
votes
1
answer
106
views
Is it always wrong to modify a list while iterating on it? and why?
I have a list containing my data, in the following form:
data = [[[1, 3, 4, 5, 7], [A, B, C]],
[[2, 3, 8, 2, 9], [F, C, C]],
[[6, 3, 1, 3, 1], [F, E, D]],
[[2, 3, 7, 0, 3], [...
0
votes
1
answer
17
views
How do I make the values I am iterating into a list stop from duplicating the entire list plus one value over and over?
The title maybe a bit confusing or if I am not supposed to post here sorry but, I am having trouble with numerical values I am putting into a list continuously with the main objective that I want to ...
1
vote
1
answer
857
views
Remove older elements from a list
I'm trying to remove similar elements from a list that contains a sub_list with the elements' name, date, and additional data:
basket = [['cheese', '2015/04/16', 'junk'],['apple', '2015/04/15', '...
0
votes
1
answer
114
views
Cleaning Data: Replacing Current Column Values with Values mapped in Dictionary
I have been trying to wrap my head around this for a while now and have yet to come up with a solution.
My question is how do I change current column values in multiple columns based on the column ...
3
votes
1
answer
1k
views
Looping through a list of object/values, remove duplicates, and return unique value in View (python)
I am trying to better understand and put into action some programming concepts, specifically looping and recursion (or iteration??) through a list that contains values. I have an api that retrieves a ...
0
votes
1
answer
70
views
Python cannot iterate a list completely
So I posted this before but I didn't follow the community guidelines so I decided to post it again this time following the community guidelines. (I tried to delete my other question but it wouldn't ...