Python Forum
Trying to write func("abcd") -> "abbcccdddd"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to write func("abcd") -> "abbcccdddd"
#4
(Oct-22-2020, 07:57 AM)Axel_Erfurt Wrote:
def tag(s):
    count = len(s)
    for i in range(count): 
        res = f"{s[:1]}{''.join([char*2 for char in s[1:]])}"
    return res
 
 
print(tag("Tom"))

Thanks for the quick response. The code you have suggested seems to print all letters twice other than the first letter. looks like we are joining the first character
{s[:1]}
with twice
char*2
every other character
for char in s[1:]
Reply


Messages In This Thread
RE: Trying to write func("abcd") -> "abbcccdddd" - by omm - Oct-22-2020, 09:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I print from within actor(func) ?? Pedroski55 2 1,069 May-01-2024, 05:35 AM
Last Post: Pedroski55
  How to output one value per request of the CSV and print it in another func? Student44 3 2,895 Nov-11-2022, 10:45 PM
Last Post: snippsat
  Func Animation not displaying my live graph jotalo 0 2,065 Nov-13-2020, 10:56 PM
Last Post: jotalo
  call func from dict mcmxl22 3 3,836 Jun-21-2019, 05:20 AM
Last Post: snippsat
  About [from FILE import FUNC] Nwb 7 5,338 Apr-21-2019, 02:46 PM
Last Post: snippsat
  Executing func() from a different folder ebolisa 2 3,184 Jan-14-2019, 10:18 AM
Last Post: ebolisa
  Correct number wrong position func. albry 5 7,584 Jan-11-2019, 04:01 PM
Last Post: Larz60+
  How can I return my list from a func? Mike Ru 3 4,083 Oct-22-2018, 01:15 PM
Last Post: buran
  list func in lambda mepyyeti 1 3,733 Mar-10-2018, 09:07 PM
Last Post: buran
  return variable in func mepyyeti 1 3,399 Mar-01-2018, 02:30 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020