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")
44 Replies
Saßì
Saßì12mo ago
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?
Yash Naidu
Yash NaiduOP12mo ago
That's great. Very simple, clean and readable.
Saßì
Saßì12mo ago
It seems like you likes to play with code 😉 If I'm wrong
Yash Naidu
Yash NaiduOP12mo ago
😅 Debugging is fun. Unlike writing code from scratch, i love to debug them and find out possible end cases.
Saßì
Saßì12mo ago
I love it too When it comes to debugging,it literally gives us some fun to work on it
Yash Naidu
Yash NaiduOP12mo ago
💯 agree.
Saßì
Saßì12mo ago
How often do you work new things ?
Yash Naidu
Yash NaiduOP12mo ago
I love to debug the C code on Linux environment. With right commands, we can literraly see which memory location is getting corrupted.
Saßì
Saßì12mo ago
That's so nice
Yash Naidu
Yash NaiduOP12mo ago
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.
Saßì
Saßì12mo ago
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
Yash Naidu
Yash NaiduOP12mo ago
Very true!
Saßì
Saßì12mo ago
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.
Yash Naidu
Yash NaiduOP12mo ago
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).
Saßì
Saßì12mo ago
Ic , VS code would be better mostly
Yash Naidu
Yash NaiduOP12mo ago
True. I am yet to explore memory tools and others within Ubuntu and try them out. Yep. Coding in Vim was fun though. 😅
Saßì
Saßì12mo ago
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
Yash Naidu
Yash NaiduOP12mo ago
Great. GDB is such a fun debugging tool ( Only if we know the right commands) Yes, did explore them.
Saßì
Saßì12mo ago
It's little complicated then other tools
Yash Naidu
Yash NaiduOP12mo ago
yes
Saßì
Saßì12mo ago
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.
Yash Naidu
Yash NaiduOP12mo ago
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.
Saßì
Saßì12mo ago
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.
Yash Naidu
Yash NaiduOP12mo ago
Thanks! it was a nice experience at last. Another day, another problem to debug.
Saßì
Saßì12mo ago
It's better to face much debugging problems,so that we can enhance our skill set It would help us to explore new things
Yash Naidu
Yash NaiduOP12mo ago
Yes, true.
Saßì
Saßì12mo ago
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
Yash Naidu
Yash NaiduOP12mo ago
Thanks! Had a great chat with you . 👏🙌
Saßì
Saßì12mo ago
It's a pleasure Talk with you. One thing do you use GCC complier ?
Yash Naidu
Yash NaiduOP12mo ago
Yes. GCC it is.
Saßì
Saßì12mo ago
Have you faced any complications while using it ?
Yash Naidu
Yash NaiduOP12mo ago
Not while running regular C code.
Saßì
Saßì12mo ago
Great
Yash Naidu
Yash NaiduOP12mo ago
i usually use something plain like gcc -o programName programName.c If its more than 1 more, id go with Makefile
Saßì
Saßì12mo ago
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 🤠
Yash Naidu
Yash NaiduOP12mo ago
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
Saßì
Saßì12mo ago
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.
Yash Naidu
Yash NaiduOP12mo ago
True true. It was indeed difficult in the beginning. But by making a habit to use Makefile, things are much simpler now.
Saßì
Saßì12mo ago
Yeah One suggestion, just try to keep as much as knowledge you can , so that you can easily tackle it
Yash Naidu
Yash NaiduOP12mo ago
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.
Saßì
Saßì12mo ago
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!
Yash Naidu
Yash NaiduOP12mo ago
Thanks @Saßì . Will be updating about my future learnings as i go through them.
Saßì
Saßì12mo ago
That's so nice , pleasure to talk with you!! I just like this server threads ,those were really helpful to share our opinions
Yash Naidu
Yash NaiduOP12mo ago
Same. I loved this server thread. The feeling's mutual. Happy to have connected with you.
Want results from more Discord servers?
Add your server