As part of data analysis using Python we may be required to to convert the data container from set to list. In this article we'll see e how to solve this requirement.With listThis is a straightforward approach in which we directly apply the list function on the given set. The elements get converted into elements of a list.Example Live DemosetA = {'Mon', 'day', '7pm'} # Given Set print("Given set : ", setA) res = (list(setA) ) # Result print("Final list: ", res)OutputRunning the above code gives us the following result −Given set : ['7pm', 'Mon', 'day'] Final list: ['7pm', 'Mon', 'day']With ... Read More
As part of data manipulation in Python we may sometimes need to convert a given number into a list which contains the digits from that number. In this article we'll see the approaches to achieve this.With list comprehensionIn the below approach we apply the str function to the given number and then convert into integer through identity function. Finally we wrap the result into a list.Example Live DemonumA = 1342 # Given number print("Given number : ", numA) res = [int(x) for x in str(numA)] # Result print("List of number: ", res)OutputRunning the above code gives us the following result −Given ... Read More
During data processing using python, we may come across a list whose elements are tuples. And then we may further need to convert the tuples into a list of strings.With joinThe join() returns a string in which the elements of sequence have been joined by str separator. We will supply the list elements as parameter to this function and put the result into a list.Example Live DemolistA = [('M', 'o', 'n'), ('d', 'a', 'y'), ('7', 'pm')] # Given list print("Given list : ", listA) res = [''.join(i) for i in listA] # Result print("Final list: ", res)OutputRunning the above code gives ... Read More
Sometimes we may be given a python list whose elements are tuples. Then we may have a data processing requirement which will need these tuples to be converted to lists for further processing. In this article, we will see how to convert a list of tuples to a list of lists.With list comprehensionIt is a straight forward approach where we create a for loop to loop through each element and apply the list function to create a list of lists.Example Live DemolistA = [('Mon', 3), ('Wed', 4), ('Fri', 7, 'pm')] # Given list print("Given list : ", listA) res = [list(ele) ... Read More
We may come across a lists whose elements are tuples. But for further data processing we may need to convert the tuples to the normal elements of a list. In this article we will see the approaches to achieve this.With list comprehensionIn this approach we design nested for loops to iterate through each tuple and produce the final list of elements.Example Live DemolistA = [('Mon', 3), ('Wed', 4), ('Fri', 7, 'pm')] # Given list print("Given list : ", listA) res = [item for t in listA for item in t] # Result print("Final list: ", res)OutputRunning the above code gives us ... Read More
Python has a wide variety of data manipulation capabilities. We have a scenario in which we are given a list which has elements which are pair of numbers as tuples. In this article we will see how to extract the unique digits from the elements of a list which are tuples.With re and setWe can use regular expression module and its function called sub. It is used to replace a string that matches a regular expression instead of perfect match. So we design a regular expression to convert the tuples into normal strings and then apply the set function to ... Read More
The scrollY property in JavaScript works the same as pageYoffset property. If you want to get the pixels the document scrolled to from the upper left corner of the window, then use the scrollY property for vertical pixels.ExampleYou can try to run the following code to learn how to work with scrollY property in JavaScript. div { background-color: yellow; height: 1500px; width: 1500px; } function scrollFunc() { window.scrollBy(200, 200); alert("Vertical: " + window.scrollY); } Scroll
The scrollX property in JavaScript works the same as pageXoffset property. If you want to get the pixels the document scrolled to from the upper left corner of the window, then use the scrollX property for horizontal pixels.ExampleYou can try to run the following code to learn how to work with scrollX property in JavaScript. div { background-color: yellow; height: 1500px; width: 1500px; } function scrollFunc() { window.scrollBy(200, 200); alert("Horizontal: " + window.scrollX); } Scroll
Use the document.images property in JavaScript to get the number of tags in a document.ExampleYou can try to run the following code to implement document.images property in JavaScript.Live Demo JavaScript Example TutorialsPoint Tutorials var num = document.images.length; document.write("How many images? "+num);
While manipulating data with python, we may come across a list which has numbers as strings. Further we may want to convert the list of strings into tuples. Of course the given strings are in a particular format of numbers.With map and evalWe will use the map function to apply eval on every element of the list. Then store the final element as a list.Example Live DemolistA = ['21, 3', '13, 4', '15, 7'] # Given list print("Given list : ", listA) # Use eval res = list(map(eval, listA)) # Result print("List of tuples: ", res)OutputRunning the above code gives us ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP