Method # 1: Using
list () + enumerate ()
A combination of the above functions can be used to accomplish this particular task. In this case, we simply pass an enumerated list to list (), which returns a tuple with the first element as the index and the second as the list element for that index.
The original list: [4, 5, 8, 9, 10 ] List after conversion to tuple list: [(0, 4), (1, 5), (2, 8), (3, 9), (4, 10)]
Method # 2: Using
zip () + range ()
A combination of the above functions can also be used to accomplish this particular task. In this we just use the ability of
zip () to convert to a tuple and
range () to get the index of the element to length. This pair indexes the value in the form of a list of tuples.
| tr> |
The original list: [4, 5, 8, 9, 10] List after conversion to tuple list: [(0, 4), (1, 5), (2, 8), (3, 9), (4, 10)]
Introduction to Machine Learning with Python: A Guide for Data Scientists 1st Edition. Machine learning has become an integral part of many commercial applications and research projects, but this f...
The role of adaptation, learning and optimization are becoming increasingly essen- tial and intertwined. The capability of a system to adapt either through modification of its physiological structure ...
A Problem-Solver’s Guide to Building Real-World Intelligent Systems. Data is the new oil and Machine Learning is a powerful concept and framework for making the best out of it. In this age of aut...
It would be easy for me to develop native apps using Java, C++ or Objective-C and I am also able to learn Kotlin, Dart or Swift, but things are much easier when you just use Python. I have done a Djan...