extract a substring from an array of strings in python -


i'm new python. know if there way extract array (or list) of substrings (all characters position 1 position 2) elements of string array (or list of strings) without making loop.

for example, have: aa=['ab1cd','ab2ef'] , , want output be: out=['b1','b2']

for single string variable out=aa[1:3], can't figure how list or array (without loop).

thanks cheers

you need some kind of loop. list comprehension easiest way:

out = [x[1:3] x in aa] 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -