Last active
September 21, 2022 19:52
-
-
Save mayankdawar/bc7d4fc0207e9575efaafbbc1b42e4c8 to your computer and use it in GitHub Desktop.
Currently there is a string called str1. Write code to create a list called chars which should contain the characters from str1. Each character in str1 should be its own element in the list chars.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| str1 = "I love python" | |
| chars = [] | |
| for i in str1: | |
| chars.append(i) |
Its Working properly
str1 = "I love python"
chars = [ ]
for char in str1 :
chars.append( i )
I did this way
str1 = "I love python"
# HINT: what's the accumulator? That should go here.
chars = []
for i in range(len(str1)):
chars.append(str1[i])
str1 = "I love python"
chars = []
for i in str1:
chars.append(i)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
str1 = "I love python"
chars = []
for i in str1:
chars.append(i)