Skip to content

Iterating the iterated list in python #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GirishMadheswaran opened this issue Feb 23, 2023 · 2 comments
Closed

Iterating the iterated list in python #47

GirishMadheswaran opened this issue Feb 23, 2023 · 2 comments

Comments

@GirishMadheswaran
Copy link

first = []
second = []
for i in range(len(fruits)):
first.append(fruits[i])
#after this method i am getting the output like below
["orange", "apple", "banana"]
for item in range(len(first)):
print(first[item])
# after this method i am getting the output like this
orange
apple
banana
#i am trying to store the above values inside the second=[]
Need an solution for this

@Akuli
Copy link
Owner

Akuli commented Feb 23, 2023

One easy way to add all items is with .extend(), see https://github.com/Akuli/python-tutorial/blob/master/basics/lists-and-tuples.md#what-can-we-do-with-lists

fruits = ['orange', 'apple', 'banana']
second = []
second.extend(fruits)
print(second)  # Output: ['orange', 'apple', 'banana']

@Niki-098
Copy link

Niki-098 commented Mar 8, 2023

second=first.copy()
print(second)

@Akuli Akuli closed this as completed Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants