Convert Set into a List in Python

Pradeep Elance
Updated on 20-May-2020 11:12:20

353 Views

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

Convert Number to List of Integers in Python

Pradeep Elance
Updated on 20-May-2020 11:10:01

11K+ Views

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

Convert List of Tuples to List of Strings in Python

Pradeep Elance
Updated on 20-May-2020 11:08:40

828 Views

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

Convert List of Tuples to List of Lists in Python

Pradeep Elance
Updated on 20-May-2020 11:06:54

427 Views

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

Convert List of Tuples into List in Python

Pradeep Elance
Updated on 20-May-2020 11:04:17

860 Views

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

Convert List of Tuples into Digits in Python

Pradeep Elance
Updated on 20-May-2020 11:02:52

207 Views

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

Role of scrollY Property in JavaScript

Ayyan
Updated on 20-May-2020 11:02:34

388 Views

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                      

Role of scrollX Property in JavaScript

Srinivas Gorla
Updated on 20-May-2020 11:01:25

577 Views

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                      

Work with Document Images in JavaScript

Arushi
Updated on 20-May-2020 11:00:53

508 Views

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);          

Convert List of Strings to List of Tuples in Python

Pradeep Elance
Updated on 20-May-2020 10:59:26

361 Views

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

Advertisements