By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

changing list items

P: n/a
hi

say i have a list

alist = ['a','b','c','e','d','f']
I wanted to change the elements , say alist[2:4] .

If i do alist[2:4] = "t" , it gives
['a', 'b', 't', 'd', 'f'] which is not what i want.
I wanted alist = ['a','b','t','t','d','f']

My list may have more elements, and i may need to replace elements from
different positions,
eg alist[10:15] , alist[30:40] etc..

thanks.

Nov 23 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
A possibile first solution:
>>alist = ['a','b','c','e','d','f']
inf, sup = 2, 4
alist[inf:sup] = ["t"] * (sup - inf)
alist
['a', 'b', 't', 't', 'd', 'f']

Bye,
bearophile

Nov 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.