1 2 3 4 in python


Asked by wiki @ & viewed by 13 persons


Python: “1-2-3-4” to [1, 2, 3, 4]

What is the best way to convert a string on the format "1-2-3-4" to a list [1, 2, 3, 4]? The string may also be empty, in which case the conversion should return an empty list [].

This is what I have:

map(lambda x: int(x),
    filter(lambda x: x != '',
           "1-2-3-4".split('-')))

EDIT: Sorry all of those who answered before I corrected my question, it was unclear for the first minute or so.

Do you know the better answer?

Similar questions

1 2 3 4 python

Asked by wiki @ & viewed by 10 persons

Python: “1-2-3-4” to [1, 2, 3, 4] What is the best way to convert a string on the format "1-2-3-4" …

Python 1 2 3 4 5

Asked by wiki @ & viewed by 9 persons

Python: “1-2-3-4” to [1, 2, 3, 4] What is the best way to convert a string on the format "1-2-3-4" …

1 2 4 5 3 6 python

Asked by wiki @ & viewed by 10 persons

Difference between “//” and “/” in Python 2 [duplicate] This question already has answers here: What is the difference between …

0 1 1 2 3 5 in python

Asked by wiki @ & viewed by 6 persons

How to write the Fibonacci Sequence? I had originally coded the program wrongly. Instead of returning the Fibonacci numbers between …

Python 1 vs 2

Asked by wiki @ & viewed by 31 persons

Difference between python 1 and 2 Just out of complete curiosity, did Python 2 add anything major to Python 1? …

Python 2 3 unicode

Asked by wiki @ & viewed by 23 persons

how to convert Python 2 unicode() function into correct Python 3.x syntax I enabled the compatibility check in my Python …

Django 2 python 3

Asked by wiki @ & viewed by 10 persons

For Python2 to Python3 code conversion, Which version of Python & Django best suited? Currently I am working in big …

Sys argv 1 python 3

Asked by wiki @ & viewed by 11 persons

sys.argv[1] meaning in script I'm currently teaching myself Python and was just wondering (In reference to my example below) in …

Performance python 2 vs 3

Asked by wiki @ & viewed by 45 persons

Python 2.7 or Python 3 (for speed)? [closed] As it currently stands, this question is not a good fit for …

Unicode python 2 vs 3

Asked by wiki @ & viewed by 9 persons

Pythonic way to ensure unicode in python 2 and 3 I'm working on porting a library so that it is …

Jupyter notebook python 2 and 3

Asked by wiki @ & viewed by 28 persons

Using both Python 2.x and Python 3.x in IPython Notebook I use IPython notebooks and would like to be able …

Python 3 vs python 2 performance

Asked by wiki @ & viewed by 30 persons

Python 2.7 or Python 3 (for speed)? [closed] As it currently stands, this question is not a good fit for …

Amazon linux 2 python 3

Asked by wiki @ & viewed by 17 persons

How do I install Python 3 on an AWS EC2 instance? I'm trying to install python 3.x on an AWS …

Mac use python 3 instead of 2

Asked by wiki @ & viewed by 21 persons

How to set Python's default version to 3.x on OS X? [duplicate] This question already has answers here: How to …

1 2 3 to 1 2 3 in python

Asked by wiki @ & viewed by 6 persons

Converting [“1, 2, 3”] to [1, 2, 3], in python? I tried: my_list = ["1, 2, 3", "4, 5, 6"] …

Most viewed questions


Python strftime milliseconds

Asked by wiki @ & viewed by 200 persons

Format a datetime into a string with milliseconds I want to have a datetime string from the date with milliseconds. …

What does the percent sign mean in python

Asked by wiki @ & viewed by 136 persons

What does the percentage sign mean in Python In the tutorial there is an example for finding prime numbers: >>> …

Self keyword in python

Asked by wiki @ & viewed by 134 persons

What is the purpose of the word 'self'? What is the purpose of the self word in Python? I understand …

Check object type python

Asked by wiki @ & viewed by 132 persons

Determine the type of an object? Is there a simple way to determine if a variable is a list, dictionary, …

Alphabetical sort python

Asked by wiki @ & viewed by 131 persons

Python data structure sort list alphabetically I am a bit confused regarding data structure in python; (),[], and {}. I …

Correlation matrix python

Asked by wiki @ & viewed by 131 persons

Plot correlation matrix using pandas I have a data set with huge number of features, so analysing the correlation matrix …

Python random

Asked by wiki @ & viewed by 127 persons

Generate random integers between 0 and 9 How can I generate random integers between 0 and 9 (inclusive) in Python? …

Python one line for loop

Asked by wiki @ & viewed by 124 persons

Python one-line “for” expression I'm not sure if I need a lambda, or something else. But still, I need the …

Python create dataframe from list

Asked by wiki @ & viewed by 124 persons

Python: create a pandas data frame from a list I am using the following code to create a data frame …

How to add a column to dataframe python

Asked by wiki @ & viewed by 123 persons

Adding new column to existing DataFrame in Python pandas I have the following indexed DataFrame with named columns and rows …

Why we use self in python

Asked by wiki @ & viewed by 116 persons

What is the purpose of the word 'self'? What is the purpose of the self word in Python? I understand …

Shape 0 python

Asked by wiki @ & viewed by 115 persons

x.shape[0] vs x[0].shape in NumPy Let say, I have an array with x.shape = (10,1024) when I try to print …

Python print working directory

Asked by wiki @ & viewed by 113 persons

Find current directory and file's directory [duplicate] This question already has answers here: How do you properly determine the current …

Image shape python

Asked by wiki @ & viewed by 110 persons

Python OpenCV2 (cv2) wrapper to get image size? How to get the size of an image in cv2 wrapper in …

Interface grafica python

Asked by wiki @ & viewed by 108 persons

Como criar interface gráfica em Python? [duplicada] Essa pergunta já tem uma resposta aqui: É possível criar interfaces gráficas para …