Question

Python: Loops and Lists def any_adjacent_combustibles(names, combustibles): Given a list of strings names, and a list...

Python: Loops and Lists

def any_adjacent_combustibles(names, combustibles): Given a list of strings names, and a list of strings combustibles, return True if there are any combustibles in the names list directly next to each other, False if not.

o Assume: names is a list of strings; combustibles is a list of strings.

any_adjacent_combustibles(['a','b','c'],['a','b','d']) → True

any_adjacent_combustibles(['a','b','c'],['c','b']) → True

any_adjacent_combustibles(['a','b','c'],['a','c']) → False

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is a code for achieving the task:

The code is well-commented and easy to understand if the answer helped you please upvote and if you have any doubts please comment i will surely help. please take care of the indentation while copying the code. Check from the screenshots provided.

Code:

def any_adjacent_combustibles(names, combustibles):
for i in range(len(names)-1):
# Check if two consecutive elements are in the combustible list
# at the same time, then return true
if names[i] in combustibles and names[i+1] in combustibles:
return True
# if the function hasn't returned yet, return false.
return False

print(any_adjacent_combustibles(['a','b','c'],['a','b','d']))
print(any_adjacent_combustibles(['a','b','c'],['c','b']))
print(any_adjacent_combustibles(['a','b','c'],['a','c']))

Add a comment
Know the answer?
Add Answer to:
Python: Loops and Lists def any_adjacent_combustibles(names, combustibles): Given a list of strings names, and a list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings...

    Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings as a parameter. The strings are intended to represent a person's first and last name (with a blank in between). Assume the last names are unique. The function should return a dictionary (dict) whose keys are the people's last names, and whose values are their first names. For example: >>> dictionary = names([ 'Ljubomir Perkovic', \ 'Amber Settle', 'Steve Jost']) >>> dictionary['Settle'] 'Amber' >>>...

  • plz solve it using ( python) spyder. use lists, loops,,,etc not allowed( def, ...) Exercise 1...

    plz solve it using ( python) spyder. use lists, loops,,,etc not allowed( def, ...) Exercise 1 Write a Python program that reads from user the names and temperatures of n cities (n must be> 0) into two lists: a list to hold the names of the cities and another one to store the temperatures of each city. Then using these two lists, your program should find and display the following information as shown in sample output below . The average...

  • def verifyMagic( matrix, num): "!" Given a list of lists called matrix, recursively verify that each...

    def verifyMagic( matrix, num): "!" Given a list of lists called matrix, recursively verify that each list sums to num. Return True if that's the case, otherwise, return false. If the list is empty, return None. Assume that the correct input types were given." # Base case 1: a matrix with no elements if return # Base case 2: a matrix with one element if # Check if the sum of the only element in the list is num. #...

  • 1. The Operand Stack - opstack The operand stack should be implemented as a Python list....

    1. The Operand Stack - opstack The operand stack should be implemented as a Python list. The list will contain Python integers, strings, and later in Part 2 code arrays. Python integers and lists on the stack represent Postscript integer constants and array constants. Python strings which start with a slash / on the stack represent names of Postscript variables. When using a list as a stack, assume that the top of the stack is the end of the list...

  • (Python) Which is true of: def Fn(data = []): Group of answer choices is a reasonable...

    (Python) Which is true of: def Fn(data = []): Group of answer choices is a reasonable idea as long as your data is a list of strings. is a bad idea because the default [] will accumulate data and the default [] will change with subsequent calls. is a good idea so that your data lists start empty with every call. is a good idea so that all calls to the function that do not provide any arguments on the...

  • def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of <lst> in...

    def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of <lst> in order. Each slice is a list of size <n> containing the next <n> elements in <lst>. The last slice may contain fewer than <n> elements in order to make sure that the returned list contains all elements in <lst>. === Precondition === n <= len(lst) >>> slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]] True >>> slice_list(['a', 1, 6.0, False],...

  • In python, please help me fill in these functions given their limitations. Please use for loops....

    In python, please help me fill in these functions given their limitations. Please use for loops. def palindrome(x): """ For a given string, determine if the string is a palindrome. (The same forward and back) Input: String of any size (including empty) Return: Boolean (True if palindrome, False otherwise) Limitation: You must use a loop. Only function allowed to be used is len (if needed). Cannot use "in" besides "for var in container" """ pass def getCount(char, strng): """ Get...

  • It's in Python 3. Please make sure it displays correct strings lenght And displays correct character...

    It's in Python 3. Please make sure it displays correct strings lenght And displays correct character lenght 1 def sum list(numbers): Sums a list of integers param numbers: a list of intege rs return: the sum of the integers in numbe rs def get_string_lengths (st rings) : 10 11 Given a list of strings, return a list of intege rs representing the lengths of the input strings :param strings: a list of strings return: a list of integers represent ing...

  • Define a function called max_association(), which recieves 2 lists, lst1, which is a list of strings,...

    Define a function called max_association(), which recieves 2 lists, lst1, which is a list of strings, and lst2, which is a list of integers. The function must return a list of strings associated to the highest integers in lst1. Assume both lists have the same length As an example, the following code fragment: L1 = ['a','b','c','d','e','f','g','h','i','j'] L2 = [1,2,3,1,3,2,3,1,2,1] result = max_association(L1,L2) print(result) should produce the output: ['c', 'e', 'g']

  • def get_indices(lst, elm): ''' (list of lists, object) -> tuple of two ints Given a list...

    def get_indices(lst, elm): ''' (list of lists, object) -> tuple of two ints Given a list of lists and an element, find the first pair of indices at which that element is found and return this as a tuple of two ints. The first int would be the index of the sublist where the element occurs, and the second int would be the index within this sublist where it occurs. >>> get_indices([[1, 3, 4], [5, 6, 7]], 1) (0, 0)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT