How can I write this in one line? [closed] - python

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()]))

Related

How to find the widest and narrowest part of an object? [closed]

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 10 months ago.
Improve this question
I am new to the world of image processing. And I am working on a project, where I need to find the narrowest and widest part of a letter/object like the one I have attached to the post. I have tried many things, but I do not get proper results. Can you help with a way to approach this. I am mostly using Python and OpenCV.
Thanks in advance!

Python selecting lists with for loop [closed]

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']]

Filtering string column with specific character [closed]

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 1 year ago.
Improve this question
I have a string column like this and want to filter content between "/" character:
A
9/17/001.a.x.y.16.04451
006.b.021017006814
2/17/000.c.m.n.15.00668/008
And the expected output is
A
001.a.x.y.16.04451
006.b.021017006814
000.c.m.n.15.00668
How could i make it done with python/R/Mysql
Thank youuu
In MySQL, you can use regexp_replace():
select t.*,
regexp_replace(a, '^[^/]+/[^/]+/([^/]*)[/|^]', '$1')
from t;
The logic is that you seem to want the third component between slashes if there is one. Otherwise, you seem to want the entire string.
Here is a db<>fiddle.

Create a list with text from another file [closed]

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")

What are different types of string/int as in data types that can be input by the person playing a game in python. (I am using pycharm) [closed]

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
How to input an integer data type as a user playing a game? I have tried many things but they don't work. I have tried inputing numbers but they still are strings not integers.
In python3 use:
x = int(input(3))
and in python2 use:
input(3)

Categories