Reverse words without using any library method.
Reverse words in a given sentence without using any library method.
What to Do : Invert the order of words in a given sentence, maintaining the order of characters within each word. (e.g.: I/P: "Hello Word" ,O/P: "World Hello")
What to Do : Invert the order of words in a given sentence, maintaining the order of characters within each word. (e.g.: I/P: "Hello Word" ,O/P: "World Hello")
44 Replies
Certainly! Here's a simple Python script that reverses the order of words in a given sentence without using any library methods:
def reverse_words(sentence):
words = sentence.split()
reversed_sentence = ' '.join(reversed(words))
return reversed_sentence
#Example Usage:
input_sentence = "Hello Word"
output_sentence = reverse_words(input_sentence)
print("Input: ", input_sentence)
print("Output:", output_sentence)
This script defines a function reverse_words that takes a sentence, splits it into words, reverses the order of the words, and then joins them back into a sentence. The example usage demonstrates how to use this function with the given input sentence "Hello Word."
@Yash Naidu what do you think?
That's great. Very simple, clean and readable.
It seems like you likes to play with code 😉
If I'm wrong
😅 Debugging is fun. Unlike writing code from scratch, i love to debug them and find out possible end cases.
I love it too
When it comes to debugging,it literally gives us some fun to work on it
💯 agree.
How often do you work new things ?
I love to debug the C code on Linux environment. With right commands, we can literraly see which memory location is getting corrupted.
That's so nice
I explore at least 1 new topic each day. Everything that is related to embedded, sometimes from Linux internals, to understanding of various RTOS, to memory, embedded devices and such. As embedded is vast, so is my exploration of topics.
Debugging in a Linux environment offers a rich set of tools that, when used in tandem, can significantly expedite the process of identifying and resolving issues in C code. It's a skill that becomes more valuable with experience and can greatly enhance the robustness of your software.
Tbh ,it's a great thing
We have to work on new things everyday so that we can able to grab new stuff . That would let us into new paths
Very true!
Do you use any other softwares to crack ?
Debugging C code on a Linux environment indeed offers a powerful set of tools and commands to analyze and diagnose issues.
Im not much familiar with the tools.
I mostly use VS code for coding part( sometimes vim) and would be compiling it on Ubuntu App( WSL2).
Ic , VS code would be better mostly
True. I am yet to explore memory tools and others within Ubuntu and try them out.
Yep.
Coding in Vim was fun though. 😅
Certainly! For your development setup using VS Code, Vim, and compiling on Ubuntu App with WSL2, here are some debugging and tool suggestions:
VS Code Debugger:
VS Code comes with a powerful built-in debugger. Set breakpoints, inspect variables, and step through your code with ease. Use the "Run and Debug" functionality to initiate debugging sessions.
VS Code Extensions:
Explore extensions in the VS Code marketplace that enhance debugging capabilities. Extensions like "C/C++" provide additional features for debugging C code etc
There are some more useful tools
Hope you were familiar with those
For sure man
Great.
GDB is such a fun debugging tool ( Only if we know the right commands)
Yes, did explore them.
It's little complicated then other tools
yes
GDB is a powerful debugger on Linux. Install it on WSL using sudo apt-get install gdb. You can then use it for debugging your compiled programs.
Yes, i do that.
Recently had a good use of it. In one of my project where i was parallelizing matrix multiplication using OpenACC, i found that i was getting an OOM Killer( Out Of Memory) and the program was stopping.
Used gdb to see which function was causing that and we, it was the multiplication one. In the end, increased the Swap File space on WSL2 as it was concsuming all the RAM. It worked at last.
That's an excellent example of effective debugging and problem-solving! Identifying the Out Of Memory issue using GDB and linking it to the matrix multiplication function shows a keen understanding of the system's behavior.
Increasing the Swap File space on WSL2 to address the RAM consumption issue demonstrates a practical solution to accommodate resource-intensive tasks. This experience not only resolved the immediate problem but also provided insights into optimizing resource management for similar parallel computing tasks in the future.
Well done on successfully navigating and overcoming this challenge in your project! It showcases the importance of debugging skills and the ability to analyze system behavior, leading to informed decisions for system optimization.
Thanks! it was a nice experience at last. Another day, another problem to debug.
It's better to face much debugging problems,so that we can enhance our skill set
It would help us to explore new things
Yes, true.
The more you work ,the more you grow
This is what I follow mostly because debugging is not a simple thing
We just have to move forward by shining up ourself
I noticed that shine yourself,keep going man. Just keep command over debugging
Thanks! Had a great chat with you . 👏🙌
It's a pleasure Talk with you. One thing do you use GCC complier ?
Yes. GCC it is.
Have you faced any complications while using it ?
Not while running regular C code.
Great
i usually use something plain like
gcc -o programName programName.c
If its more than 1 more, id go with Makefile
Your approach of using a simple compilation command for a single source file and resorting to a Makefile for more complex projects is a pragmatic and common practice
your approach aligns well with the scale and complexity of your projects. As your projects evolve, the transition to a Makefile structure becomes a natural progression, providing better organization and maintainability. It's all about choosing the right tool for the job, and your approach seems well-suited for your current needs.
If this makes sense 🤠
It does.
It's difficult to compile in the regular way if we are using multiple files with multiple flags.
Makefile is such a beast for compilation
Facts man
Absolutely, and you've captured a common sentiment among developers. Makefiles shine when dealing with larger projects involving multiple source files, dependencies, and various compilation flags.
While Makefiles might seem intimidating at first, the investment in learning and setting up a well-structured Makefile pays off in the long run, especially for projects of significant size and complexity. It becomes a powerful and indispensable tool in a developer's toolkit.
True true. It was indeed difficult in the beginning. But by making a habit to use Makefile, things are much simpler now.
Yeah
One suggestion, just try to keep as much as knowledge you can , so that you can easily tackle it
Yes. Thanks for that.
I am also posting my daily learnings on LinkedIn so that it's useful for other as well as those posts would act as a reminder for my learnings.
By incorporating Makefiles into your routine, you've not only mastered a valuable tool but also established a foundation for more efficient and enjoyable development experiences. Keep up the great work, and may your coding endeavors continue to flourish!
Thanks @Saßì . Will be updating about my future learnings as i go through them.
That's so nice , pleasure to talk with you!!
I just like this server threads ,those were really helpful to share our opinions
Same. I loved this server thread.
The feeling's mutual. Happy to have connected with you.