Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
118 views

Does python 3.12 allows to append items from the list to tuple, I am trying this but getting error TYPEERROR: 'tuple' object is not callable

Please find the below code, once I execute this code I am getting 'tuple' object is not callable error please give the solution, thanks in advance. `mytuple = ("apple", "banana", &...
Lakshmi's user avatar
-1 votes
1 answer
118 views

Why can't openpyxl append list of tuples

Edited for more detail: Trying to append a list of tuples to bottom of an Excel range using "sheet.append() without using a for loop. The list is shown in the code below. I thought "append&...
tanno oba's user avatar
-2 votes
1 answer
44 views

How to iterate through a list of tuples and make pairs out of them?

I have a list like this: point_list = [(54,8),(55,9),(56,10),(57,11)] and now I want to make them as pairs like: [(54,8),(55,9)],[(55,9),(56,10)],[(56,10),(57,11)],[(57,11),(54,8)] and I have a ...
Dein_coder's user avatar
0 votes
2 answers
67 views

printing list object with appended element not works - python

I have written a code to get list from tuple and append a number to it. I have read other posts about this, and know that list.append returns None, and None would be printed. But in my code, how can I ...
Johnny's user avatar
  • 13
-2 votes
1 answer
33 views

Why listay is not appending the elements?

I'm very new in Python and coding in general, so this question probably will sound dumb. I want to append tuples with two elements in listay: if the first element of l2 matches with any first element ...
costalucas's user avatar
-1 votes
1 answer
44 views

Find the first number is tuple in python

I have this code and this a,b and c values and after appeidnig in tuple i need to find the first number of 1 and last value from 7 ,how i can get this two first and last value from the tuple. a=1,5 b=...
Hasan's user avatar
  • 7
-3 votes
1 answer
162 views

Sorting a list of cards by face value [closed]

my input is: cards = ['Jack', 8, 2, 6, 'King', 5, 3, 'Queen'] and the expected output is [2,3,5,6,8,'Jack','Queen','King'] but generic method mean always number comes first and then alphabets ...
Mirza Jamal's user avatar
-1 votes
2 answers
115 views

Creating a list of tuples

I am a given an input file with values of data to read from, the data is given in a pair of numbers like: (1, 2), (3, 4), (3, 5), (4,9) ..etc. I must read each of these lines and make each line into a ...
zena g's user avatar
  • 35
0 votes
1 answer
19 views

When appending a tuple to a list, I can append (a + b + c) or (a, b + c) or (a + b, c) but appending (a, b ,c) causes the program to refuse to run

Here's the code def check_right_angle(a, b, c): if a**2 + b**2 == c**2: return True return False def mn_to_abc(m, n): return m**2 - n**2, 2 * m * n, m**2 + n**2 list_solutions = [...
Pedro Ferreira's user avatar
1 vote
1 answer
41 views

Trying to append common values to specific numbers in an array. PYTHON

So basically I'm trying to append numbers in a tuple like array the another number is in a specific position. Input will be: list1 = [(0, 1), (0, 2), (0, 3), (1, 4), (1, 6), (1, 7), (1, 9)] This is ...
cool's user avatar
  • 11
0 votes
2 answers
74 views

How I can append a string to the tuples in a list?

I'm creating an application that generates walking bass lines from specified chords. It always begins with the root (1st chord tone), then the permutations of the 1st, 3rd and 5th chord tones follow. ...
IanHacker's user avatar
  • 581
1 vote
1 answer
51 views

How am I able to append to a list that is inside a tuple when tuple is immutable?

as we know that tuple is immutable but if a tuple holds a list inside,can we append an respective list? t=(1,2,3,"hi",[2,3,4],True) t[4].append(7) print(t) output (1,2,3,"hi",[2,3,4,7],True)
manikishore puppala's user avatar
1 vote
1 answer
47 views

a misunderstanding about lists and multiple iterations

I am in high school taking programming classes in Python and I came across something weird. I think this is just my mistake but i don't know why when typing : L = [] x = [] for i in range(4): x....
joniboy's user avatar
  • 55
2 votes
1 answer
1k views

Haskell: How do I append to a list of list of tuples?

Sorry, I just started learning Haskell. I don't understand how to append a tuple to each sublist. My current list is: [[("String", "String", 2.0)],[("String", "String", 2.0),("String", "String", 2.0)...
Natti's user avatar
  • 101
0 votes
1 answer
2k views

Add 2 coordinates to an index in a list in Python, and algebra

I want to have a 2 or 3D list in Python containing endpoints to 10 separate lines where I can pass the y-coordinates as a function of x in range(10). y=((x+1)/2)*x for x in range(10 or however long). ...
peer's user avatar
  • 162
0 votes
2 answers
470 views

Python 3, how to append tuples into list

I just started to learn python. I need to store a csv file data into a list of tuples: tuples to represent the values on each row, list to store all the rows. The function I have problem with is when ...
Ace_J's user avatar
  • 87
1 vote
2 answers
151 views

fastest way to append paired data to list [duplicate]

I have a list of data called ID, and another list called Dates. They are paired data, and the lists are of equal lengths, approximately 800,000 items long each. I want to pair each item from each list,...
Andrew Louis's user avatar
3 votes
4 answers
120 views

Appending miniature lists to a larger list

I'm creating a python application to play the game Perudo (or Liar's dice). I am trying to create a function that calculates all the possible moves that the player (or AI) is allowed to make and ...
Tom Burrows's user avatar
  • 2,325
-3 votes
1 answer
148 views

How to separate a tuple with 2 parts into separate lists?

So I have a tuple that has two lists in it: x = (['a', 's', 'd'], ['1', '2', '3']) How do I make it into two lists? Right now my code basically looks like: list1.append(x[1]) list1.append(x[2]) ...
S. Martin's user avatar
1 vote
2 answers
75 views

how to add elements of a list into another list with no bracket and no imports in python?

Im trying to put specific number of elements of a list in a list like: L = [1,2,3,4] and say I want point 1 - 3 to get put back in to the list giving me: L = [1,2,3,4,2,3,4] but i keep getting: L ...
Adam Spencer Baker's user avatar
0 votes
1 answer
694 views

Comparing two lists of tuples and finding the frequency of the common elements

I have two lists of tuples: myList1=[(1,2,3,4),(5,6,7),(8,9,10,11,12)] myList2=[(1,2,7,6,2,1,3),(5,3,2,1,8,9,6),(11,12,1,2,5,6,6)] I want to find the frequency of the elements in myList2, which are ...
PythonNoob's user avatar
78 votes
5 answers
323k views

Append a tuple to a list - what's the difference between two ways?

I wrote my first "Hello World" 4 months ago. Since then, I have been following a Coursera Python course provided by Rice University. I recently worked on a mini-project involving tuples and lists. ...
Skywalker326's user avatar
  • 1,206
-4 votes
1 answer
2k views

Why do I get an invalid syntax error in this piece of code, Python? [closed]

Code: students = [] choice = None while choice != 0: print( """ 0 - Exit 1 - Show all students 2 - Add a student """ ) choice = input("Choice: ") print() ...
Shaheedul  Islam's user avatar
1 vote
1 answer
13k views

Python list append to list "AttributeError: 'tuple' object has no attribute 'append'"

Alright so I know you cannot append a tuple to a list. However I am still receiving this error despite my best efforts. Can someone tell me what I am doing wrong or what is going on? Traceback (...
user3586062's user avatar
  • 1,339
2 votes
5 answers
5k views

Inputting Numbers Into Empty List Python

I'm in the process of writing a program that demonstrates linear search, but I'm stuck with one of the steps I'm taking. In this step, I'm trying to get the program to take an input list of numbers ...
Goose LaMoose's user avatar
1 vote
2 answers
483 views

.split() and .append information from .txt file as tuples to a new list

I'm trying to read a .txt file line by line with a while loop, split each line at a comma intersection, call a function to return the "date" side of each line to a list, then append the "task" side to ...
exclamationmark1's user avatar
3 votes
3 answers
9k views

How to append one value to every tuple within a list?

How to append 1 value to every tuple within a list? tuple_list = [('a','b'),('c','d'),('e','f')] value = 111 Desired_List = [(111,'a','b'),(111,'c','d'),(111,'e','f')] I've tried the following: ...
Chris's user avatar
  • 5,794
0 votes
2 answers
122 views

how do i make list of list python

Extracting data from Excel sheet for value in quoted.findall(str(row[2])): i.append(value.replace('"', '').strip()) print i Then i get a set of lists as below ['M', 'N', 'O'] ['P', 'Q', 'R'] ['...
WEshruth's user avatar
  • 777
0 votes
3 answers
92 views

iterating through a list to append a value to variable lists

I have the following data: data = [['AB', 'BS, BT'], ['AH', 'AH'], ['AS', 'AS, GS']] I would like to iterate through the lists of list to produce a list of tuples. new_data = [('AB', 'BS'), ('AB', '...
hylaeus's user avatar
  • 255
7 votes
6 answers
2k views

Why does the content of a tuple changes when I append to a list inside of it but does not change when I update a variable?

myVar = ["jhhj", "hgc"] myTuple = ([1,2,3], [4,5,6], myVar) myVar.append('lololol') print myTuple Why and how can this tuple be modified by appending after construction? myVar = "lol" myTuple = ([1,...
Web Master's user avatar
  • 4,330
-2 votes
4 answers
1k views

Python, is this a bug, append to a list within a tuple results in None? [duplicate]

This is one of the shortest examples I've written in a long time I create and update a tuple3 In [65]: arf=(0,1,[1,2,3]) In [66]: arf=(arf[0],arf[1], arf[2] ) In [67]: arf Out[67]: (0, 1, [1, 2, 3]...
Bryan Hunt's user avatar
  • 3,783
0 votes
5 answers
2k views

Appending tuples to lists, assigning index

I'm working on a chemistry program which requires a list of all elements and their corresponding atomic mass units, something along the lines of: Elements = [(H,1),(He,2)...(C,12)] all the elements ...
user1036197's user avatar
0 votes
3 answers
427 views

How to dump/append all the values of a dict into a list if key is a tuple?

I have a dict as follows with unit names and testnames in a list: dictA = {('unit1', 'test1'): 10, ('unit2', 'test1'): 78, ('unit2', 'test2'): 2, ('unit1', 'test2'): 45} units = ['unit1', 'unit2']...
siva's user avatar
  • 2,145