Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9099827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:43:00+00:00 2026-06-17T00:43:00+00:00

I am a new Python programmer and trying some stuff out. I want to

  • 0

I am a new Python programmer and trying some stuff out. I want to create a list of strings and loop through my list to check the size of each element, if the size is greater than 5, then I will change that string into an uppercase string. I am stuck on how to access that element. Below is some of the code that I have written. Thank you in advance!

lis = ['heeeeellllooo','world','low','higggghhh']
for elem in list:
  if len(lis[elem]) > 5:
    list[elem].upper()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:43:02+00:00Added an answer on June 17, 2026 at 12:43 am

    use a list comprehension with ternary operator:

    In [16]: lis = ['heeeeellllooo','world','low','higggghhh']
    
    In [17]: [x.upper() if len(x)>5 else x for x in lis] # this is a new list
    
    Out[17]: ['HEEEEELLLLOOO', 'world', 'low', 'HIGGGGHHH']
    

    You can also use enumerate(), enumerate returns a tuple whole first item is the index of the element and the second item is the element itself.

    This method modifies the original list.

    In [18]: for index,elem in enumerate(lis):
       ....:     if len(elem)>5:
       ....:         lis[index]=elem.upper()  #access element by index
       ....:         
    
    In [19]: lis
    Out[19]: ['HEEEEELLLLOOO', 'world', 'low', 'HIGGGGHHH']
    

    How are lists implemented?:

    Python’s lists are really variable-length arrays, not Lisp-style
    linked lists. The implementation uses a contiguous array of references
    to other objects, and keeps a pointer to this array and the array’s
    length in a list head structure.

    This makes indexing a list a[i] an operation whose cost is independent
    of the size of the list or the value of the index.

    When items are appended or inserted, the array of references is
    resized. Some cleverness is applied to improve the performance of
    appending items repeatedly; when the array must be grown, some extra
    space is allocated so the next few times don’t require an actual
    resize.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new programmer in Python and I am trying to do some
I am a new Ruby programmer and have been looking through some tutorials for
I am a RoR programmer new to Python. I am trying to find the
I'm a new Python programmer who is making the leap from 2.6.4 to 3.1.1.
I'm a new Python programmer who is having a little trouble using 'self' in
First, I'm not a python programmer. I'm an old C dog that's learned new
I am a bit new to Python, but an experienced programmer. I am writing
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
Im new two python and am trying to grow a dictionary of dictionaries. I
I am new python programmer,what I have understood so far,yield keyword returns an object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.