Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1978 of 2650
512 Views
Tuples are python collections or arrays which are ordered but unchangeable. If we get a number of tuples where the first element is the same, then we may have a scenario when we need to add the second elements of those tuples whose first elements are equal.Using map and for loopIn this method we will first consider a list made up of tuples. Then convert them to dictionary so that we can associate the elements in the tuple as key value pair. Then we apply the for loop with summing the value for each key o the dictionary. Finally use ... Read More
9K+ Views
Python has capability to create GUI applications using the Tkinter library. The library provides many methods useful for GUI applications. The geometry method is a fundamental one which decides the size, position and some other attributes of the screen layout we are going to create.Example - 1In the below program we create a window of size 22x200 pixels using the geometry method. Then we add a button to it and decide button position in the window using the side and pady options.Examplefrom tkinter import * base = Tk() base.geometry('200x200') stud = Button(base, text = 'Tutorialspoint', font =('Courier', 14, 'bold')) stud.pack(side ... Read More
4K+ Views
During manipulating data using python lists, we come across a situation where we need to know if two lists are entirely different from each other or they have any element in common. This can be found out by comparing the elements in the two lists with the below approaches decribed.Using InIn a for loop we use the in clause to check in an element is present in the list or not. We will stretch this logic to compare the elements of the lists by choosing an element from first list and checking its presence in the second list. So we ... Read More
485 Views
Tkinter is the library which gives GUI programming capability to python programs. As part of GUI creation we need to create screen layouts of different sizes and depth. In this program we will see how to calculate the size of a screen in terms of pixels as well as in mm. We can also get the depth of the screen in pixels. There are various methods available as part of Tkinter which we use for this.Examplefrom tkinter import * # creating tkinter window base = Tk() #screen's length and width in pixels and mm length_1= base.winfo_screenheight() width_1= base.winfo_screenwidth() length_2 = ... Read More
370 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given al list, we need to display the smallest number available in the listHere we can either sort the list and get the smallest element or use the built-in min() function to get the smallest element.Now let’s observe the concept in the implementation below −Example Live Demolist1 = [101, 120, 104, 145, 99] # sorting using built-in function list1.sort() print("Smallest element is:", list1[0])OutputSmallest element is: 99All the variables are declared in the local scope and their references are seen in the figure ... Read More
721 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given two integers, we need to print the second maximum value in the dictionaryNow let’s observe the concept in the implementation below−Approach 1 − Using sorted() function by negative indexesExample Live Demo#input example_dict ={"tutor":3, "tutorials":15, "point":9, "tutorialspoint":19} # sorting the given list and get the second last element print(list(sorted(example_dict.values()))[-2])Output15Approach 2 − Here we use sort method on the list and then access the second largest elementExample Live Demolist1 = [11, 22, 1, 2, 5, 67, 21, 32] # using built-in sort method list1.sort() # ... Read More
4K+ Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to display the second largest number in a list.There are three approaches to solve the problem−Approach 1 − We use the set() function & remove() functionExample Live Demolist1 = [11, 22, 1, 2, 5, 67, 21, 32] # to get unique elements new_list = set(list1) # removing the largest element from list1 new_list.remove(max(new_list)) # now computing the max element by built-in method? print(max(new_list))Output32Approach 2 − We use sort() method and negative indexesExample Live Demolist1 = [11, 22, 1, 2, ... Read More
2K+ Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a string, we need to find the occurrence of each character in a given string.Here we will be discussing 3 approaches as discussed below:LApproach 1 − The brute-force approachExample Live Demotest_str = "Tutorialspoint" #count dictionary count_dict = {} for i in test_str: #for existing characters in the dictionary if i in count_dict: count_dict[i] += 1 #for new characters to be added else: count_dict[i] = 1 print ("Count of all characters in Tutorialspoint ... Read More
1K+ Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to calculate the largest element of the list.Here we will take the help of built-in functions to reach the solution of the problem statementUsing sort() functionExample# list list1 = [23, 1, 32, 67, 2, 34, 12] # sorting list1.sort() # printing the last element print("Largest element is:", list1[-1])OutputLargest in given array is 67Using max() functionExample Live Demo# list list1 = [23, 1, 32, 67, 2, 34, 12] # printing the maximum element print("Largest element is:", max(list1))OutputLargest in given ... Read More
1K+ Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to calculate the largest element of the array.Here we use the bruteforce approach in which we compute the largest element by traversing the whole loop and get the element.We can observe the implementation below.Example Live Demo# largest function def largest(arr, n): #maximum element max = arr[0] # traverse the whole loop for i in range(1, n): if arr[i] > max: max = arr[i] return max # ... Read More