- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a program in Python to find the maximum length of a string in a given Series
Input −
Assume, we have a Series like this, [“one”, “two”, “eleven”, “pomegranates”, “three”] and the maximum length of the string is “Pomegranates”
Solution
To solve this, we will follow the below approaches.
Define a Series
Set the initial value of a maxlen is 0
Set the “maxstr” value is initially empty string.
Create a for loop and access all the values in the Series one by one and create an if condition to compare the value based on the length as follows −
for i in res: if(len(i)>maxlen): maxlen = len(i) maxstr = i
Finally, print the value stored in the “maxstr” variable.
Example
Let us see the following implementation to get a better understanding.
import pandas as pd res = pd.Series(["one","two","eleven","pomegranates","three"]) maxlen = len(res[0]) maxstr = "" for i in res: if(len(i)>maxlen): maxlen = len(i) maxstr = i print(maxstr)
Output
pomegranates
- Related Articles
- Write a Python program to find the maximum value from first four rows in a given series
- Write a program in Python to resample a given time series data and find the maximum month-end frequency
- Write a program in Python to find the index for NaN value in a given series
- Write a Python program to remove a certain length substring from a given string
- Write a Python program to shuffle all the elements in a given series
- Write a program in Python to round all the elements in a given series
- Write a program in Python to filter valid dates in a given series
- Write a program in Python to filter armstrong numbers in a given series
- Write a program in Python to print the power of all the elements in a given series
- Write a program in Python to print the day of the year in a given date series
- Write a program in Python to find the missing element in a given series and store the full elements in the same series
- Write a program in C++ to find the maximum and second maximum in a given unsorted array of integers
- Write a program in Python to filter only integer elements in a given series
- Write a program in Python to find the most repeated element in a series
- Write a program in Python to slice substrings from each element in a given series

Advertisements