Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Out put i am looking for is a sbelow. can you please let me know where i am going wrong ? Python 3.6 is the

Out put i am looking for is a sbelow. can you please let me know where i am going wrong ? Python 3.6 is the code below

string = '''['photo.jpg, Warsaw, 2013-09-05 14:08:15', 'john.png, London, 2015-06-20 15:13:22', 'myFriends.png, Warsaw, 2013-09-05 14:07:13', 'Eiffel.jpg, Paris, 2015-07-23 08:03:02', 'pisatower.jpg, Paris, 2015-07-22 23:59:59', 'BOB.jpg, London, 2015-08-05 00:02:03','notredame.png, Paris, 2015-09-01 12:00:00', 'me.jpg, Warsaw, 2013-09-06 15:40:22', 'a.png, Warsaw, 2016-02-13 13:33:50', 'b.jpg, Warsaw, 2016-01-02 15:12:22', 'c.jpg, Warsaw, 2016-01-02 14:34:30', 'd.jpg, Warsaw, 2016-01-02 15:15:01', 'e.png, Warsaw, 2016-01-02 09:49:09', 'f.png, Warsaw, 2016-01-02 10:55:32', 'g.jpg, Warsaw, 2016-02-29 22:13:11']'''

def prefixed_number(n, max_n): len_n = len(str(n)) len_max_n = len(str(max_n)) prefix = ''.join(['0' for i in range(len_max_n-len_n)]) + str(n) return prefix def solution(S): list_of_pics = S.split(' ') city_dict = {} for pic in list_of_pics: city = pic.split(', ')[1] if city in city_dict: city_dict[city].append(pic) else: city_dict[city] = [pic] final_string = "" for city_group in city_dict: city_dict[city_group]#.sort(key=fetch_date_time) for ind,photo in enumerate(city_dict[city_group]): #city_dict[city_group].sort(key=fetch_date_time) city = photo.split(',')[1] ext = photo.split(',')[0].split('.')[1] max_len = len(city_dict[city_group]) number = prefixed_number(ind+1, max_len) city_dict[city_group][ind] = city + number + '.' + ext + ' ' final_string += ''.join(city_dict[city_group]) return final_string print(solution(string))

Output I need: Warsaw02.png London1.png Warsaw01.jpg Paris2.jpg Paris1.jpg London2.jpg Warsaw03.jpg Warsaw09.png Warsaw07.jpg Warsaw06.jpg Warsaw08.png Warsaw04.png Warsaw05.jpg Warsaw10.jpg

Output I am getting: Warsaw01.jpg Warsaw02.png Warsaw03.jpg Warsaw04.png Warsaw05.jpg Warsaw06.jpg Warsaw07.jpg Warsaw08.png Warsaw09.png Warsaw10.jpg London1.png London2.jpg Paris1.jpg Paris2.jpg

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

What does intelligence have to do with leadership?

Answered: 1 week ago