Recursion to write a python function

Assignment Help Python Programming
Reference no: EM13163654

Use recursion to write a Python function depth(LL), where LL is a nested list of lists of lists etc. of numbers (i.e., oat and int) and strings. We want to return the depth of nesting, i.e., how often, maximally, there is a list in a list etc. in LL. You may use the function type(..).
Examples for testing: Single integers, oats and strings have depth 0. In ['a',9] and in [ ] the depth of nesting is 1, since there is no list in a list. In [2,[1],1,[3,2],[5,-1,0.1],1] and in [[ ]] the depth is 2, since there is a list within the list (but no list in a list in a list). In [2,[1,-1,[3,2],[ ],3],1,4,['ab']] and in [[[ ],[ ]],[ ]] the depth is 3; there is a list in a list in a list. In [2,[2,[3],[1,[2]]],1,[2,2]] the depth is 4. Similarly, one could give examples of depth could be 5, 6, etc.


The following auxiliary function create a sample list:

def listsample():
L = []
for i in range(10):
L = L + [L[len(L)//2:]+[i,[i-1]]]
return L[:]

How do you use your depth function to nd the depth of this sample list? Give the calls and their output (as comments).

Reference no: EM13163654

Questions Cloud

Write a function trans(m) which returns the transpose : Write a function trans(M) which returns the transpose of an n-by-n matrix M. The matrix M is represented by a list of n lists, each of length n. Transposing M means that each M[i][j] is swapped (once!) with M[j][i].
True or false about networking : 2- A print queue must be set up for every printer on the network served by a print server. True False
Permutation ciphers : Permutation Ciphers (a.k.a. Transposition Ciphers) are another class of simple cryptosystems. For this we use the functions apply(.,.) and inv(.) from Homework 4; copy these two functions into your le as auxiliary functions.
Function should return a dictionary : Write a function numOccur(s), where s is a string; the function should return a dictionary whose keys are the 26 ascii letters abcdefghijklmnopqrstuvwxyz
Recursion to write a python function : Use recursion to write a Python function depth(LL), where LL is a nested list of lists of lists etc. of numbers (i.e., oat and int) and strings. We want to return the depth of nesting, i.e., how often, maximally, there is a list in a list etc
Determine the values for m and l for the b+ tree : A B+-tree is to be stored on disk whose block size is 2048 bytes. The data records to be stored are 50 bytes, and their key is 4 bytes. Determine the values for M and L for the B+-tree. Assume pointers are 4 bytes each.
Let ll be a list of integers : Let LL be a list of integers. Use list comprehension to produce teh following lists. Each one should just take onel line. Anser questions as two comments.
Write a select statement that returns these columns : Write a SELECT statement that returns these columns from the Products table: The date_added column A column that uses the CAST function to return the date_added column with its date only (year, month, and day)
You will write a program that reads a text file : You will write a program that reads a text file, counts the number of words in the file, and the number of occurrences of each character. It will print to a file the number of words, and the number of occurrences of each character, as well as the ..

Reviews

Write a Review

Python Programming Questions & Answers

  Design a prgram using python

Design a prgram USING PYTHON that students can use to calculate what score they need on final exam to get a certan final grade for a course.

  The initial number for generating the sequences

Then, after the functions, read in the initial number for generating the sequences. Here, check that it is a positive integer. If it is not, give an error message and exit the program.

  Data file is a comma separated

The data file is a comma separated text values stored in a file with '.CSV' extension. The file has five columns corresponding to employee data fields listed above.

  Cleint software so that it does not display

Rewrite the cleint software so that it does not display an echo of a message sent by the users. Maybe it means that each time a user tries to send a private message that same message is also sent back to them? summary: stop that from happening?

  Fill in the python code

Fill in the Python code to play Tic Tac Toe. I won't award points unless it runs succesfully. # Tic-Tac-Toe Game def drawBoard(board): # Draws the board using the list of numbers print(" ") print(" ",board[0]," | ",board[1]," | ", board[2]) print("--..

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  Program to do the enciphering

Write a program to do the enciphering. It should prompt the user for a message, and print out both the entered message and its corresponding ciphertext.

  The dictionary order based on the ascii order

Needless to say, the dictionary order based on the ASCII order is not what a real-world indexing software wants. So, we want to implement the dictionary order of strings in the standard wa

  Let ll be a list of integers

Let LL be a list of integers. Use list comprehension to produce teh following lists. Each one should just take onel line. Anser questions as two comments.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd