Linked Questions

240 votes
6 answers
351k views

Given two lists: x = [1,2,3] y = [4,5,6] What is the syntax to: Insert x into y such that y now looks like [1, 2, 3, [4, 5, 6]]? Insert all the items of x into y such that y now looks like [1, 2, 3, ...
Soumya's user avatar
  • 5,432
152 votes
7 answers
195k views

Why do these two operations give different results? >>> c = [1, 2, 3] >>> c [1, 2, 3] >>> c += c >>> c [1, 2, 3, 1, 2, 3] >>> c = [1, 2, 3] >>> c....
ooboo's user avatar
  • 17.3k
16 votes
6 answers
76k views

I want to create this tuple: a=(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7),(8,8,8),(9,9,9) I tried with this a=1,1,1 for i in range (2,10): a=a,(i,i,i) However it creates a tuple ...
HolyCrack's user avatar
  • 181
7 votes
2 answers
14k views

I start out with an empty list and prompt the user for a phrase. I want to add each character as a single element of the array, but the way I'm doing this creates a list of lists. myList = [] for i ...
Heitor Chang's user avatar
  • 6,057
10 votes
6 answers
5k views

I can do append value to a tuples >>> x = (1,2,3,4,5) >>> x += (8,9) >>> x (1, 2, 3, 4, 5, 8, 9) But how can i append a tuples to a tuples >>> x = ((1,2), (3,4), (...
Hardy's user avatar
  • 1,539
33 votes
2 answers
6k views

I am new to Python and am trying to write a function that will merge two dictionary objects in python. For instance dict1 = {'a':[1], 'b':[2]} dict2 = {'b':[3], 'c':[4]} I need to produce a new ...
nasia jaffri's user avatar
3 votes
1 answer
8k views

Python lists have a += operator as well as append and extend methods. If l is a list, is l += ... equivalent to l.append(...), l.extend(...), both, or neither?
user200783's user avatar
  • 14.5k
2 votes
1 answer
12k views

Hi could someone help with this code,i am getting the error: " 'int' object is not iterable " at line 28(A.extend(n)) since i am new to python i am unable to figure out a solution any help is ...
yade123's user avatar
  • 71
-1 votes
2 answers
2k views

I am using a recursive function to create a flow path through a maze. The function returns the correct path tuples (row,col), but I need it in the form of a List of tuples. For example I need to ...
user2278537's user avatar
2 votes
3 answers
799 views

The idea is to repeat list's elements with each different n times as below. ls = [7, 3, 11, 5, 2, 3, 4, 4, 2, 3] id_list_fname = ['S11', 'S15', 'S16', 'S17', 'S19', 'S3', 'S4', 'S5', 'S6', 'S9'] ...
rpb's user avatar
  • 3,307
3 votes
1 answer
3k views

I am reading two columns of values out of a .csv file a line at a time, which yields a list of row entries made up of two strings (something like ['cat1', 'dog1']) When I iterate over all the rows I ...
Andy Kellett's user avatar
1 vote
1 answer
5k views

I'm new to python. I tried to store bunch of strings to an array and at the end print out the array, however it print out as a long list of characters. here is my code: user_with_no_records = [""] ...
user468587's user avatar
  • 5,071
3 votes
1 answer
4k views

For Python list, is append() the same as +=? I know that + will lead to the creation of a new list, while append() just append new stuff to the old list. But will += be optimized to be more similar to ...
deltadu's user avatar
  • 49
-3 votes
3 answers
3k views

values = [] records = contains two records of different person values.extend((records.name, records.age , records.gender)) print values This will print [some_name,age,gender , ...
Santhosh's user avatar
  • 229
0 votes
2 answers
546 views

Im trying to loop through a list in python and split words based on characters. I want to return a 1 dimension list as the result. Example wordlist = ['border\collie', 'dog\cat', 'horse\hound'] # ...
user5067291's user avatar

15 30 50 per page
1
2 3 4 5
13