8
['0-0-0', '1-10-20', '3-10-15', '2-30-20', '1-0-5', '1-10-6', '3-10-30', '3-10-4']

How can I remove all the hyphens between the numbers?

Neuron
  • 5,141
  • 5
  • 38
  • 59
Hodgson Xue
  • 119
  • 1
  • 1
  • 2
  • 1
    [`str.replace`](https://docs.python.org/3/library/stdtypes.html#str.replace) for example. Your question seems overly generic. Did you try solving it yourself first? – poke Dec 04 '16 at 01:13
  • 3
    Look at the answers [here](http://stackoverflow.com/questions/22187233/how-to-delete-all-instances-of-a-character-in-a-string-in-python). – Bijay Gurung Dec 04 '16 at 01:13
  • 4
    There are countless similar questions already on StackOverflow. Your first step shoudl be to read the documentation (you will find many string methods there). Your next step before posting a new question is seeing if such a question has been asked already. – juanpa.arrivillaga Dec 04 '16 at 01:17
  • Welcome to Stackoverflow. Please, read these links to guide on how SO works and for your questions: [Tour](http://stackoverflow.com/tour) | [How to ask](http://stackoverflow.com/help/how-to-ask) | [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) – Tom Dec 04 '16 at 01:19

2 Answers2

15

You can just iterate through with a for loop and replace each instance of a hyphen with a blank.

hyphenlist = ['0-0-0', '1-10-20', '3-10-15', '2-30-20', '1-0-5', '1-10-6', '3-10-30', '3-10-4']
newlist = []

for x in hyphenlist:
    newlist.append(x.replace('-', ''))

This code should give you a newlist without the hyphens.

SamOh
  • 199
  • 6
10

Or as a list comprehension:

>>>l=['0-0-0', '1-10-20', '3-10-15', '2-30-20', '1-0-5', '1-10-6', '3-10-30', '3-10-4']
>>>[i.replace('-','') for i in l] 
['000', '11020', '31015', '23020', '105', '1106', '31030', '3104']
LMc
  • 12,577
  • 3
  • 31
  • 43