Ad
How To Remove The First And Last Value Of The First And Last Element That Is Separated By (.) And Need To Join The Other Elements In The List
I have a python-list like this
['6403687.6403773','6404555.6404614','6413270.6413335']
In this I need to remove first value of the first element(6403687) and last value of the last element(6413335) and need to join the other element like this ['6403773.6404555','6404614.6413270'].Like this I have several list with n values.I don't how to do this.If anyone please help me.
list = ['6403687.6403773','6404555.6404614','6413270.6413335']
After removing the first and last values,I need a list like this
list1 = ['6403773.6404555','6404614.6413270']
Ad
Answer
This method would do it step by step and works also for lists or arbitrary length:
number_strings = ['6403687.6403773','6404555.6404614','6413270.6413335']
# remove first part of element
number_strings[0] = number_strings[0].split('.')[1]
# remove last part of last element
number_strings[-1] = number_strings[-1].split('.')[0]
# remove points
number_strings_rearranged = []
for element in number_strings:
for part_string in element.split('.'):
number_strings_rearranged.append(part_string)
# restructure with points
number_strings = [number_strings_rearranged[i]+'.'+number_strings_rearranged[i+1] for i in range(0, len(number_strings_rearranged)-1, 2)]
print(number_strings)
Output:
['6403773.6404555', '6404614.6413270']
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad