[Tutor] Question regarding lists and manipulating items in lists.
Oscar Benjamin
oscar.j.benjamin at gmail.com
Wed Jan 16 00:50:56 CET 2013
On 15 January 2013 23:40, Scurvy Scott <etanes.rm at gmail.com> wrote:
[SNIP]
>
> Anyways, the problem I'm having is I'm not really sure how to search a list
> for multiple elements and remove just those elements. Below is my code so
> far, and information y'all could provide would be appreciated. Thanks.
Perhaps you'd like to use a list comprehension to filter out the
values you are interested in:
>>> my_list = [1,4,12,3,5,2,1,45,6,32]
>>> my_filtered_list = [x for x in my_list if x%2] # only the odd numbers
>>> print my_filtered_list
[1, 3, 5, 1, 45]
>
> import mingus.core.notes as notes
> #fibonacci
> def fib(num1,num2):
> a, b = 0, 1
> for i in xrange(num1,num2):
> c = b % 12 #modulo 12 on each generated fibonacci number
> a_list= [notes.int_to_note(c)] #using Mingus to translate the Fib mod12
> numbers into notes and then (I think) storing each one as an element in a
> list?
> a, b = b, a+b #this is just the algorithm for the fibonacci numbers
Please post in plain-text rather than html as it screws up the code
formatting (see above).
Oscar
More information about the Tutor
mailing list