Question

1. Using list comprehension and a single line of code, flatten a given list of lists....

1. Using list comprehension and a single line of code, flatten a given list of lists. For example your line of code must give [1, 2, 3, 4, 5, 6] out of [[1, 2], [3, 4], [5, 6]].

2. Using list comprehension, and without using any imported module, write a Python function to return a list of email addresses in a given phrase of text. Inside your function you must do this with a single line of code.

For example, for the given phrase of , "Interested faculty are encouraged to send a letter indicating their interest in this opportunity by April 26 to info@asccc.org or cs110a@asccc.org or call @ +1-900-900-90. Feedback will be provided to those submitting letters. The formal application process, with additional details, will be published shortly thereafter" must return the list, [info@asccc.org, cs110a@asccc.org].

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# 1
ll = [[1, 2], [3, 4], [5, 6]]
result = [val for lst in ll for val in lst]
print(result)


# 2
def get_emails(s):
    return [word for word in s.split() if '@' in word and '.' in word]


s = "Interested faculty are encouraged to send a letter indicating their interest in this opportunity by April 26 to info@asccc.org or cs110a@asccc.org or call @ +1-900-900-90. Feedback will be provided to those submitting letters. The formal application process, with additional details, will be published shortly thereafter"
print(get_emails(s))
Add a comment
Know the answer?
Add Answer to:
1. Using list comprehension and a single line of code, flatten a given list of lists....
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
  • In python,Using list comprehension create an expression that sums up all the factors of an positive...

    In python,Using list comprehension create an expression that sums up all the factors of an positive integer number. For example, if the number is 6, then the output should be 12 (i.e., 1+2+3+6 =12). Your answer should be only one line of code.

  • Given a list of integers, return a list where each integer is added to 1 and...

    Given a list of integers, return a list where each integer is added to 1 and the result is multiplied by 10. You must use a list comprehension math1([1, 2, 3]) → [20, 30, 40] math1([6, 8, 6, 8, 1]) → [70, 90, 70, 90, 20] math1([10]) → [110] Complete in Python code the starter code is listed bellow def math1(lst):    return lst print(math1([1, 2, 3])) # [20, 30, 40] print(math1([6, 8, 6, 8, 1])) # [70, 90, 70,...

  • In Java: Assume the "ferrets" variable points to a linked list of "LLNode." Write code that...

    In Java: Assume the "ferrets" variable points to a linked list of "LLNode." Write code that traverses the list and prints the following. Do not forget to consider the case where the list is empty. The "LLNode" class is given: public class LLNode { protected T info; protected LLNode link; public LLNode(T info) { this.info = info; link = null; } public void setInfo(T info) { this.info = info; } public T getInfo() { return info; } public void setLink(LLNode...

  • a) 7% Define a function (the function definition only) named combine_lists that receives two lists of...

    a) 7% Define a function (the function definition only) named combine_lists that receives two lists of integers (the function has 2 parameters). You can assume that each list is the same length and each list is not empty. The function will create a new list which is composed of the addition of each element of the two lists. The function returns the new list. For example, if the function is sent this list: [2,4,6,8,10] and this list: [5,6,7,8,9] then the...

  • Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a...

    Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...

  • In C please After exploring an old shipwreck, you recovered the captain's logs for an old...

    In C please After exploring an old shipwreck, you recovered the captain's logs for an old pirate ship. It was stored on an old waterproof USB flash drive. (Who knew pirates were so technologically advanced!). After recovering the data, you see the log is stored as an array of strings: char* log[] = { "Yarr, it be the first day since we set sail.", "We be now deep in the seas. Not a soul fer miles.", "Blimey! There been movement...

  • Using a doubly linked list as the underlying data structure, implement a list ADT that implements...

    Using a doubly linked list as the underlying data structure, implement a list ADT that implements the ListInterface.java found in the ProgProjTwo Eclipse project starting point for this assignment. In addition to the forward iterator defined by resetIterator( ) and getNextItem( ) in ListInterface.java, implement a backwards iterator by providing resetBackIterator( ) and getPreviousItem( ) methods. As noted in the syllabus addendum, you are encouraged to develop a find( ) helper method that can support various list ADT operations. A...

  • ***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a...

    ***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful.  Also note that the function must work no matter how many nodes...

  • Using C(89). A fashion retailer has decided to provide discount codes to teachers and students during...

    Using C(89). A fashion retailer has decided to provide discount codes to teachers and students during a promotional event. The first step is to verify the teacher/student status of people requesting discount code by their email addresses. They will check if the email addresses end with ".edu" and find the domain name if it does before further verification. Write a program to find the domain name of an email address if the domain name ends with .edu. The program displays...

  • Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write...

    Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write the solution to a file named p2.py and upload it here. Comprehensions will show up at the midterm exam, so it's important to practice. a) Write a list comprehension that returns a list [0, 1,4, 9, 16, .. 625] starting from range(0, 26). (lots of list elements were omitted in ...) b) Write a list comprehension that returns the list...

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