Public question

is there is a list (on the list there is str and int) , how i convert it to uppercase ?

I’d probably do this with a generator.

But if you don’t have generators under your belt yet, you might try iterating over the indices of the list, and using isinstance on each element, replacing elements as needed.

Do you mean something like this?

data = [3, 9, 5, 'hello', 'goodbye', 12, 15, 'spam', 11, 'eggs']

# do something with data...
# -> prints [3, 9, 5, 'HELLO', 'GOODBYE', 12, 15, 'SPAM', 11, 'EGGS']

If this is what you want, you need to make a decision:

  • Do you want to modify the original list, or create a new list?

Then you either:

  • Iterate over the list. If the item is a string, replace it with the uppercase version.

  • Or, create a new list, but copying each element from the original list into the new list, changing it to uppercase if it is a string.

Here are the tools you need to do this:

# Iteration
for item in some_list:

# Iteration with position:
for position, item in enumerate(some_list):
    print(item, "is at position", position)

# Check whether a value is a string.
print(isinstance(value, str))

# Uppercase a string.
print('hello world'.upper())

Does this help?