Skip to main content

Posts

Showing posts from March, 2020

Learning the Enumerate()

After, the list lets learn about the intriguing enumerate function in python. Python is the favorite programming language of many developers; contrary to popular belief, it isn’t merely a “technology for newbies” its power and functionality make it an excellent tool for a plethora of tasks. Python is renowned for its collection of libraries, modules, and functions that it comes packaged with and enumerate() is something we should learn in detail.           So, what is enumerate function?           Python's enumerate function is tool that allows us to create a counter alongside values we're iterating over: as part of a loop, for example. Enumerate takes an iterable type as its first positional argument, such as a list, and returns an enumerate object containing a number of tuples: one for each item in the iterable. Each tuple contains an integer counter, and a value from the iterable. If we ever have to iterate through a list while keeping track of the index

Further into the lists..

So, let's continue our learnings about the lists in python!      Why and how  to use list comprehension ? List is one of the most useful collection data type in python.It is a collection which is ordered and changeable.It Allows duplicate members.   Many of us would have thought of what if we want to manipulate each and every  list element? Suppose you are given a list of numbers and you want to add 1 to each element in your list: my_list = [1, 3, 3, 7] my_list_plus_one = my_list + 1  and if you have thought of some code like above then its not gonna  work. You would get this error:   TypeError : can only concatenate list (not "int") to list.  Python thinks that you want to add a list and an integer together, which doesn’t make any sense. So how do we manipulate the list? The answer is using list comprehension syntax. Example: my_list_plus_one = [num + 1 for num in my_list] print(my_list_plus_one)  # Output: [2, 4, 4, 8] Essentially, you can iterate through my_list  using

Getting started with coding

It's been while since we posted! So,let's continue our project. One of the essential data structures that we'll be using extensively is "SETS" in python. Just for the essence,here's a quick look at it: ******** CODE *********       my_list = [] my_set = set() my_list.append('a') my_set.add('a') print(my_list)  # Output: ['a'] print(my_set)  # Output: {'a'} my_list.append('b') my_set.add('b') print(my_list)  # Output: ['a', 'b'] print(my_set)  # Output: {'b', 'a'} my_list.append('a') my_set.add('a') print(my_list)  # Output: ['a', 'b', 'a'] print(my_set)  # Output: {'b', 'a'} ******** END ********** The reason behind using SETS over LISTS is elements in a set are unique and unordered. By using this data structure,we can build our vocabulary for the application. Learn more about SETS in python : https://

Selecting the database and starting the code..

   So before we proceed to the main code of the game we need to select the word database which will contain all the words that computer will pick randomly and give to the player.   We picked the database of words from following link...    https://www.mit.edu/~ecprice/wordlist.10000 Our Game gives an option to the player to select the difficulty level of the game so we give him/her the option of selecting  the number of attempts. So how to write a function to pick a random word will be shown in coming blogs. Thank you, Siddhesh Ramajgol