Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
2 answers
32 views

TCL - A condition for an item while appending items to a list

I have this list set csv [list] lappend csv [list \ a \ b \ c \ [expr {[cfg::get enable_all_columns] ? { d } : {} }] \ e \ f \ g] I need to add element d only if enable_all_columns is 1. The problem ...
Razvan's user avatar
  • 1
-1 votes
1 answer
41 views

List assigning to another variable, then original variable also changes when there will happen an operation on child variable [duplicate]

a = [1,2,4] b=a b.insert(1,45) print(a,b) results a = [1,45,2,4] b = [1,45,2,4] why a is changing is there any way, where b will change
Starpower Power's user avatar
0 votes
1 answer
234 views

Insert an element at a specific position in a list at each video frame in python

I am struggling to get a list of 4 elements (so a fixed number of elements) at each frame, if in the detected frame I don't have 2 classes, the fixed list puts 0 to the counter. this is my code : ...
Souchan's user avatar
-1 votes
1 answer
461 views

Append elem to a list replace all list element to the last item I append

I'm trying to fight really strange behaviour. I'm reading radio frames at my raspberry pi and each frame that I receive I append to the list. I noticed that appending specific element cause replacing ...
KyluAce's user avatar
  • 980
1 vote
4 answers
168 views

Set value of list item based on last defined value in list

I have a list of lists as follows. ogList = [[a], [b], [], [], [c], [d], []] I'd like each empty list to be populated like so, based on the last list which does have a value. outputList = [[a], [b], [...
noah's user avatar
  • 11
-1 votes
1 answer
106 views

What accounts for the “side effect” of appending items to a Python list by the insert() method? [duplicate]

I've seen the assertions: " It is not possible to insert at the end of the list with insert(), as that’s what the append method does”. Here is a piece of Python code that shows some very peculiar ...
O.K's user avatar
  • 7
0 votes
4 answers
39 views

I have a list [(620.9, 234.5), (591.6, 205.4), (823.4, 205.8)]. After every element i want to insert an element(x,y) after every element

I want to insert element (x,y) in such a way that the list [(620.9, 234.5), (591.6, 205.4), (823.4, 205.8)] containing x and y cordinates becomes [(620.9, 234.5),(621.9, 234.5), (591.6, 205.4), (...
Vineet Vinayak's user avatar
0 votes
1 answer
35 views

adding numpy arrays to specific indices of a list

I have a list of numpy arrays and want to add two more arrays as the first (0) and last (-1) indices of the list. These are my list and arrays: import numpy as np first_arr = np.array([1,1,1]) ...
Link_tester's user avatar
  • 1,061
0 votes
2 answers
283 views

insert n in list x --> append list x to list y --> delete n in list x

I'm trying to insert the number "1" to the list in every position with a for loop and eventually get all possible lists in python. For Example: l = ["2","3","6"]...
Kimimaro's user avatar
0 votes
3 answers
93 views

How to insert a list into a list at a specific location?

I have a list as following List_a = [1, 0, 0, 0, 1, 1] I want to insert [0, 3] into index 1. How it should look like: New_List_a = [1, [0,3], 0, 0, 1, 1] Any ideas?
Kazkuris's user avatar
0 votes
1 answer
22 views

Appending and inserting user input values to a list which dose not already have them included

drinksList = ["Fanta", "CocaCoal", "7up"] userDrink = input("What soft drink are you looking for?") if userDrink in drinksList: print(userDrink,"is in ...
Popeye's user avatar
  • 1
-3 votes
3 answers
993 views

How do I insert list in nested list [duplicate]

how do I insert list 'lst' into the first possition of the 'n_lst'? n_lst = [['I', 'dont'], ['know', 'what']] lst = ['whatever', 'whatever2'] what I need: [['whatever', 'whatever2'], ['I', 'dont'], [...
Kateřina Veselá's user avatar
1 vote
1 answer
636 views

How can i create list and add elements in python?

I am adding below readable code for creating a 'list' and all methods of add element. Here is the code: Create list. Add element using append(),insert() # Create lists list1 = [1,4,6,8] # integer ...
Rajesh Nalkanthiya's user avatar
0 votes
1 answer
61 views

Problem while inserting/appending to a list of lists

When I run the following code with n = 2, I'm getting answer = [[2, 2, 2], [1, 2], [2, 2, 2]]. n = int(input()) answer = [[1]] for i in range(2, n+1): t = [i]*((2*i)-3) answer.insert(0,...
Hirdyanshu Arora's user avatar
0 votes
2 answers
4k views

How to put string variables into a Python array?

I'm rather new at this (it's my first question ha!), and my english isn't as good and technical as yours so I apologize in advance. That being said, I'm trying to fit string variables to an array but ...
Guillermo Pérez's user avatar
-4 votes
7 answers
769 views

Problem related to Python insert() method

I make a list of the first 10 square numbers. Here’s how I might put the first 10 square numbers into a list: square=[] for i in range(1,10): square.insert(-1,i**2) print(square) ...
Fuad Fatali's user avatar
0 votes
1 answer
36 views

C ++ Cannot use insert to append values after a iteration on list

I have the following list, which prompts a user to write an student name, followed by a prompt for 3 grades in three exams obtained per student. I would like to append the name of the student if his ...
Roger Almengor's user avatar
5 votes
2 answers
12k views

A way to insert a value in an empty List in a specific index

Is there a way to insert a specific value into a List into a specific index. List should be completely empty: L = [] L.insert(2,177) print(L) L should give out the values of L [ , ,117].
user avatar
0 votes
1 answer
48 views

Try to make a function that will identify players and add two players' cards to left or right side

An empty list is given, and I am trying to make a function which will identify player so that player1's cards will be added to left side of the empty list, and player2's cards will be added to right ...
Code Vanessa's user avatar
5 votes
4 answers
815 views

Why doesn't a.insert(-1, x) mimic a.append(x)?

So I have the following Python code, which appends numbers 1-10 to the list values: values = [] for value in range(1, 11): values.append(value) print(values) And, as expected, gives us [1, 2, ...
user avatar
3 votes
2 answers
1k views

Insert an element in la list by index without moving others

I want to add elements to an empty list by index. For instance I want to add 4 to the 5th place of list a. x = 4 a = [] in other languages like C++ I could create an array with 10 indices and all ...
peykaf's user avatar
  • 79
0 votes
1 answer
38 views

Build a Loop that Sums Values and Adds to a List in a Certain Position in Python

I’m working on creating a loop that calculates income distribution based on tax returns. Let me give a simple example. Please keep in mind that this will only be a subset of the data I need to produce,...
Alex Durante's user avatar
2 votes
4 answers
24k views

'NoneType' object has no attribute 'insert' Python List append insert

I have the following problem: I create an array and then I turned it to a list, to which I want to add two more values. I have tried with append and with insert but I becoma the error message: '...
GeMa's user avatar
  • 149
0 votes
1 answer
44 views

breaking appended list into indexes

So right now i have code that gives me [-1], [1], [-1], [-1], [2], [3], [4], [-1], [5], [6], [7], [-1], [-1], [-1], [8], [9], [-1], [-1], [-1], [10]] but i want it to look like so myVV = [[-1, 1, -...
learner's user avatar
  • 137
0 votes
1 answer
88 views

Compare N lists and insert/append blank entries where discrepancies exist

I'm attempting handle several long lists (around 2000 entries in each). The goal is to sort of "diff" the lists by looking at them side by side and seeing where differences exist. Example: a = ['...
relaytheurgency's user avatar
0 votes
2 answers
142 views

Python: identical items in list are treated as the same

I have a nested list in python. Each item the second list is also a nested list. My goal is to duplicate one list, insert it right at the same index, and then modify each one. So, example of start ...
Hank's user avatar
  • 569