How to perform string operations on every element of a list of strings?

0 votes
I have a list of strings. I want to perform some operations on every element of the string. How to do it?
Jul 18, 2019 in Python by Neel
• 3,010 points
49 views

1 answer to this question.

0 votes

This can be done using list comprehension in Python. List comprehension is an elegant way to define and create list in python. We can create lists just like mathematical statements and in one line only. The syntax of list comprehension is easier to grasp. For example,

# below list contains square of all odd numbers from
# range 1 to 10
odd_square = [x ** 2 for x in range(1, 11) if x % 2 == 1]
print(odd_square) # This will print [1,9,25,49,81]
answered Jul 18, 2019 by Arvind
• 2,980 points

Related Questions In Python

0 votes
0 answers

How to perform string operations on every element of list ?

I have a list of words in ...READ MORE

Jul 18, 2019 in Python by Neel
• 3,010 points
31 views
0 votes
1 answer

How to sort a list of strings?

Basic answer: mylist = ["b", "C", "A"] mylist.sort() This modifies ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,350 points
90 views
0 votes
1 answer

How to sort a list of strings?

Try  items = ["live", "like", "code", "cool", "bug"] ...READ MORE

answered Jul 27, 2018 in Python by Priyaj
• 57,530 points
50 views
0 votes
1 answer

How to convert each list item into string in a column of data frame. ?

Hey, To split a string you can use ...READ MORE

answered Feb 5 in Python by Roshni
• 400 points
74 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 639 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 2,980 points
850 views
0 votes
1 answer

How to get a list of built in modules in Python?

simply open the python shell and type ...READ MORE

answered Aug 1, 2019 in Python by Arvind
• 2,980 points
148 views