Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solving a nested list
#1
I have to write a function that takes an integer nested list and integer parameters(nl, i). The function has to determine whether i is contained in the nested list nl and return True.
I have made the following code, but I know I am missing something;

def exercise5(nl, i):
   if type(i)==type(1):
      return True
print(exercise5( [[9, 4, 5], [3, 8]], 3))
Could someone help with finalizing the code?
Reply
#2
Finalizing is an understatement. Your function returns True if i is an int and None otherwise. This is unrelated to the question.
Reply
#3
Yeah, I know that there is a lot to do on the code, but I don't know what to do. Could you help me make it?
Reply
#4
SNIP

try this code, cant think other than to recurse the function and perform the task as u wish
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  List all possibilities of a nested-list by flattened lists sparkt 1 926 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Updating nested dict list keys tbaror 2 1,292 Feb-09-2022, 09:37 AM
Last Post: tbaror
  Python Program to Find the Total Sum of a Nested List vlearner 8 4,940 Jan-23-2022, 07:20 PM
Last Post: menator01
  Looping through nested elements and updating the original list Alex_James 3 2,147 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  shuffle a nested list giorgosmarga 11 11,954 Nov-12-2020, 07:04 PM
Last Post: perfringo
Question Save list with nested list into CSV SpongeB0B 1 5,396 Oct-12-2020, 07:26 AM
Last Post: bowlofred
  Struggling with nested list gr3yali3n 3 2,333 Jul-09-2020, 05:30 PM
Last Post: DPaul
  How to Solving non-linear equation using scipy.optimize fsolve with variable list djhak 3 4,551 Jun-10-2020, 04:12 PM
Last Post: Gribouillis
  Nested Dictionary/List tonybrown3 5 3,175 May-08-2020, 01:27 AM
Last Post: tonybrown3
  Help removing asterisk item in a nested list. bmcguire 3 2,611 Apr-06-2020, 02:35 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020