0

I am very new to programming in Python but I was wondering whether you could help me.

I have this code below:

>>> fruit  = [[""for column in range(4)]for row in range(4)] 
>>> fruit
[['', '', '', ''], ['', '', '', ''], ['', '', '', ''], ['', '', '', '']]
>>> fruit[0][0] = "strawberry"
>>> fruit[0][1] = "apple"
>>> fruit[0][3] = "banana"
>>> fruit
[['strawberry', 'apple', '', 'banana'], ['', '', '', ''], ['', '', '', ''],       ['', '', '', '']]

What i want to do to test the code is be able to iterate through each item in the list and for it to let me know where there isn't an item in the list. So it starts at [0][0] finds strawberry (and returns nothing) so carries on then it finds apple at [0][1] (and returns nothing) then at [0][2] there is nothing there so.... can it return to me [0][2] = no item? Do I need to use some kind of if else statement?

I hope you can make sense of what I want to be able to achieve and appreciate any feedback.

Many Thanks,

Richie

  • Yes, you need to check that value with an **if** and take appropriate action. – Prune Nov 23 '16 at 18:45
  • TigerHawk, I think you dup-hammered this prematurely. Your cited original returns the coordinates of a given item; this wants to detect null entries and report the omission. Since OP already knows how to access 2D elements, I don't see where the dup applies. – Prune Nov 23 '16 at 19:01
  • Thanks Prune, any suggested code with how with how to detect null entries and report the omission space please? – Richie Shaw Nov 23 '16 at 19:16
  • Nope. That's your job as the student. You should already know how to write a comparing **if** statement and print a useful message. StackOverflow is not a coding or tutorial service. We'll help you fix problem code, but we don't code for you at this level. – Prune Nov 23 '16 at 19:25
  • understood Prune, thanks – Richie Shaw Nov 23 '16 at 19:31

0 Answers0