Question

In: Computer Science

IN PYTHON: i have a list of strings: ['1,099', '1,749', '119', '129', '129', '13,299', '149', '15,299',...

IN PYTHON:

i have a list of strings:

['1,099', '1,749', '119', '129', '129', '13,299', '149', '15,299', '159', '159', '175', '179', '179', '186', '189', '189', '199', '2,549', '226', '257', '290', '3,755', '35,279', '390', '399', '399', '4,549', '415', '415', '498', '499', '499', '499', '499', '549', '60', '819', '849', '89', '89', '899', '899', '899', '899', '999']

and i want to remove the commas from each string containing a comma, and then convert each element to an integer. (for example, i have '1,099' but want 1099, and do this for every one)

Solutions

Expert Solution

b = ['1,099', '1,749', '119', '129', '129', '13,299', '149', '15,299', '159', '159', '175', '179', '179', '186', '189', '189', '199', '2,549', '226', '257', '290', '3,755', '35,279', '390', '399', '399', '4,549', '415', '415', '498', '499', '499', '499', '499', '549', '60', '819', '849', '89', '89', '899', '899', '899', '899', '999']


# splitting using comma
# joing using no delimeter
# coverting to integer

for i in range(len(b)):
b[i] = int(''.join(b[i].split(',')))
  
print(b)

# Please up vote


Related Solutions

Using Python:     "We have a list of strings: \n",     "```python\n",     "CharList = ['a',...
Using Python:     "We have a list of strings: \n",     "```python\n",     "CharList = ['a', 'b', 'c', 'd']\n",     "```\n",     "Now, we write a program to delete some elements from the list. <br> \n",     "The indexes of the elements to be deleted are stored in IndexList <br>\n",     "\n",     "```Scenario-1```: IndexList = [3, 0]\n",     "```python\n",     "CharList = ['a', 'b', 'c', 'd']\n",     "IndexList = [3, 0]\n",     "for n in range(0, len(IndexList)):    \n",    ...
Design a function in python that takes a list of strings as an argument and determines...
Design a function in python that takes a list of strings as an argument and determines whether the strings in the list are getting decreasingly shorter from the front to the back of the list
Restaurant X   Restaurant Y 85   104 117   130 119   149 151   119 262   174 183   130...
Restaurant X   Restaurant Y 85   104 117   130 119   149 151   119 262   174 183   130 125   114 148   127 157   129 216   130 336   129 308   141 175   227 111   209 151   294 145   123 92   93 233   138 235   240 181   146 155   140 196   206 164   147 120   146 60   134 203   146 181   157 114   131 136   167 174   130 184   238 194   238 227   252 194   234 350   234 307   165 210   88 198   104...
Python This part involves creating a function that will manage a List of unique strings. The...
Python This part involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test program that takes a string as input and then calls the function over and over until the...
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
In python I have a linked list. I want to create one function that takes in...
In python I have a linked list. I want to create one function that takes in one parameter, head. In the function, cur = head and next_cur = head.next. I want to return head and next_cur, except at the end of the function they will return alternating values from head. For example, if the these are the values in the linked list: 2, 3, 5, 7, 11 after the function head should return: 2, 5, 11 and next_cur should return:...
Write a program that uses Python List of strings to hold the five student names, a...
Write a program that uses Python List of strings to hold the five student names, a Python List of five characters to hold the five students’ letter grades, and a Python List of four floats to hold each student’s set of test scores. The program should allow the user to enter each student’s name and his or her four test scores. It should then calculate and display each student’s average test score and a letter grade based on the average....
This is the code what I have for doubly linked list for STACK. This is Python...
This is the code what I have for doubly linked list for STACK. This is Python language and I want anyone to help me with the following questions. Can you check for me if it is good Doubly Linked List? ####THIS IS THE ENTIRE ASSIGNMENT#### ADD the Following feature: Include a class attribute in the container class called name. In the implementation - Pod: You should ask the user to enter the name of the container and the program should...
r = range(10, 40, 3) def print_lv(strings): strings = strings if isinstance(strings, list) else [strings] for...
r = range(10, 40, 3) def print_lv(strings): strings = strings if isinstance(strings, list) else [strings] for string in strings: st = "f'" + string + ": {" + string + "}'" print_stmt = 'print(' + st + ', end="; ")' # Uncomment the following print statement to see the statement to be executed. # Each will appear on a separate line. # print(f'\n{print_stmt}') exec(print_stmt) print() print_lv(['list(r)', 'r[-2:3:-1]', 'list(r[-2:3:-1])']) OUTPUT: list(r): [10, 13, 16, 19, 22, 25, 28, 31, 34, 37];...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT