# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] colab_type="text" id="v_7As_kZOnrE"
# ### Longest Even Length Word
# Consider a string, sentence, of space-separated words where each word is a substring consisting of English alphabetic letters only.
# We want to find the first word in sentence having a length which is both an even number and greater than or
# equal to the length of any other word of even length in the sentence. 
#
# For example, if sentence is `Time to write great code` , then the word we're looking for is Time .
#
# While code and Time are of maximal length, Time occurs first. 
# If sentence is `Write code for a great time` , then the word we're looking for is code.  

# + colab={} colab_type="code" id="uVkk0tAROpMa"
data1 = 'One great way to make predictions about an unfamiliar nonfiction text is to take a walk through the book before reading.'
data2 = 'photographs or other images, readers can start to get a sense about the topic. This scanning and skimming helps set the expectation for the reading.'
data3 = ' testing very9 important'
# -

#Importing necessary packages
import pandas as pd
import numpy as np


#Function for Splitting Words
def splitword(data):
    temp={}
    data.lower()
    split_data=data.split()
    for i in range(0,len(split_data)):
        temp.update({split_data[i]:len(split_data[i])})
        output=pd.DataFrame(temp.items(),columns=['word','count'])
    return output


# + colab={} colab_type="code" id="QHYzvKW0OxYI"
#Function for finding Longest Even word
def q01_longest_even_word(sentence):
    test=splitword(sentence)#Call to the function created above
    if (test['count']%2==0).any():
        output=test.word[test[test['count']%2==0]['count'].idxmax()]
    else:
        output=0
    return output


# + colab={} colab_type="code" id="SqOygkyJOzgh"
q01_longest_even_word(data3)

StarcoderdataJupyterScriptsDedupFiltered