subject

Exercise 9.2.9: Strings To Integers5 points
Make a function called safe_int that takes a single argument. This function should try to convert the argument into an integer. If this succeeds, the function should return that integer. Otherwise, the function should return 0.

Then, use this function in a list comprehension to create a list out of the given list. The new list should contain either a 0 or the correct integer in place of every string in the given list:

[0, 2, 7, 0]
Make sure to print out the resulting list.

This is my code so far(i dont know what's wrong with it):
list_of_strings = ["a", "2", "7", "zebra"]

# Your code here...
def safe_int():
list = [int(x) if x. isdigit() else 0 for x in list_of_strings]
print list

safe_int()

but its asking "Function "safe_int" should take exactly 1 argument" and "You should use safe_int in a list comprehension", i dont know how to fix this code please help

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 02:30
These factors limit the ability to attach files to e-mail messages. location of sender recipient's ability to open file size of file type of operating system used
Answers: 2
question
Computers and Technology, 23.06.2019 03:30
In vista and windows 7, the appearance and personalization option allows you to change the
Answers: 1
question
Computers and Technology, 23.06.2019 10:20
Suppose there is a relation r(a, b, c) with a b+-tree index with search keys (a, b).1. what is the worst-case cost of finding records satisfying 10 < a < 50 using this index, in terms of the number of records n1, retrieved and the height h of the tree? 2. what is the worst-case cost of finding records satisfying 10 < a < 50 and 5 < b < 10 using this index, in terms of the number of records n2 that satisfy this selection, as well as n1 and h defined above? 3. under what conditions on n1 and n2, would the index be an efficient way of finding records satisfying the condition from part (2)?
Answers: 1
question
Computers and Technology, 24.06.2019 10:30
Which of the following types of software is most applicable to the promotion of new products through advertising? a.databases b. spreadsheets c. web design programs d. word processing tools
Answers: 2
You know the right answer?
Exercise 9.2.9: Strings To Integers5 points
Make a function called safe_int that takes a singl...
Questions
question
Mathematics, 22.11.2019 00:31
question
Mathematics, 22.11.2019 00:31
Questions on the website: 13722363