Python 2.7.2+ (Oct 4 2011)
Ubuntu 11.10 (unity removed, using Gnome Classic)
gedit
User Profile
Collapse
Profile Sidebar
Collapse
James Carpenter
Last Activity: Mar 2 '12, 01:20 AM
Joined: Feb 13 '12
Location:
-
Adding elements of list into a string
Good day,
I am trying to use a list of integers and strings, take certain elements out, and concatenate them into a string.
i.e.
Code:lista = [0,'f',0,1,1,1,0,'a',8] split_length = 3 stringa = '' while split_length >= 0:[INDENT]print 'XX ',[/INDENT][INDENT]for idx in lista:[/INDENT][INDENT][INDENT]stringa = stringa + str(lista[idx]) + ' ',[/INDENT][/INDENT][INDENT]print 'XX'[/INDENT]
XX 0 f 0 XX
... -
-
list / index
let's say I have a list
list1 = [0,0,0,0,0,0,1,0 ,0,0,0,0,1,1,1, 0,0,0,1,0]
now I have another list
list2 = [5,9,10]
What I am trying to do is check the value of each index in list2, for that index in list1
i.e.
list2, index(0), is 5, I want to check the value of the index(5) in list1
I was thinking a for loop with an if loop inside it, but I'm not sure how to call the corresponding...
No activity results to display
Show More
Leave a comment: