Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to add items to a list that are from another file.
This is what I have so far:
book_list = open("books.txt")
book_titles = []
I have no clue where to go from here.
The book titles in the text file each have their own line.
Can someone please resolve me of my ignorance? Thank you
Use the .split() function and split by each new line!
book_list = open("books.txt")
books_titles = book_list.read().split("\n")
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
There are my lists:
i1,i2,i3,i4,i5 = [],[],[],[],[]
and I need the string "test" to be appended to each list. How can I do that?
I thought about using a loop but couldn't manage to do that.
Are there any other ways to append to all the five lists?
easy busy
i1,i2,i3,i4,i5 = 5*[['test']]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I would like to create this for loop, but the text in the loop is quoted.
How can this be done please?
Thank you!
https://prnt.sc/tvutcl
in your image is in quotes, is an f-string, but they forgot to add the f
year = [2016,2017,2018,2019,2020]
for i in year:
rtx_price = (data.loc[f'{year}-07-31', 'RTX'])
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Hey So I'm working on a problem that asks me to manipulate a dictionary by grabbing all the keys and values and formatting them into a single string for every key/value pair. I have to do this in one line, or so I think, the problem is better explained in the image.
I believe they would like you to write for country, pop in country_pop.items(): on line 7. However, you can do the entire thing in one line as well.
print('\n'.join([f'{key} has {value} people' for key, value in country_pop.items()]))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
how can we write this single statement code into multiple lines?
I can understand only for loop written in multiple lines. Anyone, please break this code into multiple line code.
amp.append([amp[i] for i in ida])
By a for loop:
l = []
for i in ida:
l.append(amp[i])
amp.append(l)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
This is the Html code for the drop down menu with list of cities:
I just want to loop through all of the cities using python. BTW I am trying to create a web scraper, and have no api for the site :(
Just for anyone with the same issue you can just use the xpath and find the index pattern.