Computers and Technology, 10.02.2020 03:56 maddy6882
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
Answers: 3
Computers and Technology, 21.06.2019 22:00
Business professionals of america, and future business leaders of america – phi beta lambda are both open to business students at which levels? check all that apply. elementary school middle school high school college
Answers: 1
Computers and Technology, 22.06.2019 18:30
If an improvement creates no significant change in a product’s performance, then it is a(n) ? a0 design improvement. (there are no answer choices)
Answers: 1
Computers and Technology, 23.06.2019 23:30
What are "open-loop" and "closed-loop" systems
Answers: 1
Computers and Technology, 25.06.2019 01:00
Regular maintenance is a key component of automotive lift safety.
Answers: 1
Exercise 9.2.9: Strings To Integers5 points
Make a function called safe_int that takes a singl...
Make a function called safe_int that takes a singl...
Mathematics, 04.02.2020 01:58
Computers and Technology, 04.02.2020 01:58
History, 04.02.2020 01:58
Arts, 04.02.2020 01:58
Mathematics, 04.02.2020 01:58
Mathematics, 04.02.2020 01:58
Mathematics, 04.02.2020 01:58
Social Studies, 04.02.2020 01:58
History, 04.02.2020 01:58
Mathematics, 04.02.2020 01:58