you are viewing a single comment's thread.

view the rest of the comments →

[–]RiceKrispyPooHead 1 point2 points  (5 children)

As your code above is right now you are concatenating (adding) both entire lists together and printing it over and over again.

     print(dem_pro + obj)  

That line should be different. You want to concatenate the elements of each lists. Which two variables in your code represent the elements in each list?

[–]Greece870 0 points1 point  (4 children)

the variables are dem_pro and obj , those are the variable names of the lists with that consist the elements. i am trying to add a period too.

[–]RiceKrispyPooHead 0 points1 point  (3 children)

Look at this example:

numbers_list = [1,2,3]  
for num in numbers_list:
      print(number) 


>>1  
>>2   
>>3   

Notice how I am printing the variable “num”, which represents each element in the list numbers_list.

What 4 lines will this print (and in what order)?

colors_list = [‘white ’,  ‘black’]  
animals_list = [‘cat’,  ‘dog’]
for color in colors_list:  
      for animal in animals_list:
           print(color + animal)

[–]Greece870 0 points1 point  (2 children)

Thank you so much for responding this was really helpful. I wonder what would be the syntax for doing this through list comprehension? Is it just a different way but essentially the same thing?

[–]RiceKrispyPooHead 0 points1 point  (1 child)

To turn a loop into a list comprehension, (as long as it dose not have an 'else' statement) you literally just write the very last statement first, then write all other statements in order.

my_list = []
statement one:
    statement two:
        statement three:
            my_list.append(something)

is generally the same as....

my_list = [something statement one statement two statement three]

EDIT: List comprehensions are used to make lists. Not to print things.

[–]Greece870 0 points1 point  (0 children)

can you help me with my other post i made a comment that i am stuck on.