Use enumerate:

In [3]: user_details = [{'name':x, 'rank':i} for i,x in enumerate(ranked_users)] 

In [4]: user_details
Out[4]: 
[{'name': 'jon', 'rank': 0},
 {'name': 'bob', 'rank': 1},
 {'name': 'jane', 'rank': 2},
 {'name': 'alice', 'rank': 3},
 {'name': 'chris', 'rank': 4}]

PS. My first answer was

user_details = map(lambda (i,x): {'name':x, 'rank':i}, enumerate(ranked_users))

I'd strongly recommend using a list comprehension or generator expression over map and lambda whenever possible. List comprehensions are more readable, and tend to be faster to boot.

Answer from unutbu on Stack Overflow
🌐
w3resource
w3resource.com › python-exercises › lambda › python-lambda-exercise-46.php
Python: Find all index positions of the maximum and minimum values in a given list using lambda - w3resource
July 12, 2025 - ... # Define a function ... specifies a lambda function to evaluate each element by its value max_result = max(enumerate(nums), key=(lambda x: x[1])) # Find the minimum value and its index in 'nums' using 'min' function ...
Discussions

python - Can I use index information inside the map function? - Stack Overflow
Your function will be passed a tuple, with (index, value). In Python 2, you can specify that Python unpack the tuple for you in the function signature: ... Note the (i, el) tuple in the lambda argument specification. More on stackoverflow.com
🌐 stackoverflow.com
indexing - How to make an index static for a python lambda expression - Stack Overflow
The result is 6, I would expect the result to be 1. How can I make the index inside the lambda expression static without writing t[1]+1, i.e. using a variable? ... Python's closures are late binding. More on stackoverflow.com
🌐 stackoverflow.com
[aws-lambda-python] Unify `entry` field betwen aws-lambda-nodejs and aws-lambda-python
However, the entry and index are broken into two distinct properties in aws-lambda-python. From the docs: aws-cdk/packages/@aws-cdk/aws-lambda-python/README.md ... So, when I was converting a function over to PythonFunction, I fully specified the entry, like I would with NodejsFunction: More on github.com
🌐 github.com
10
August 7, 2020
"Unable to import module 'index': No module named 'index'"
Take a look at your code in the lambda console and your zip file, I think your index.py is inside python dir. More on reddit.com
🌐 r/Terraform
8
July 4, 2023
🌐
StrataScratch
stratascratch.com › blog › how-to-use-python-lambda-functions
How to Use Python Lambda Functions - StrataScratch
December 7, 2023 - Adjust GDP Growth: By applying lambda functions, we identified countries with the slowest economic growth, revealing potential employment and poverty challenges.( lambda function with map() ) Urbanization Index: We used lambdas to create an index that combines urban growth with population density, offering a new perspective on urbanization.( Lambda Function with apply() )
🌐
Google Groups
groups.google.com › g › vim_dev › c › Ks5Jq3Ux-1s
Finding an item using a lambda function in a List using the index() function
This lambda function will be called with two arguments: the index of the item and the value of the item. If this function returns true, then the search will stop. Currently the index() function accepts four arguments (the first two arguments are mandatory and the last two arguments are optional).
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › python-map-with-index
Get access to the Index in the map() function in Python | bobbyhadz
Copied!my_list = ['apple', 'banana', ... print(index, item) # 👉️ 0 apple, 1 banana, 2 melon · Notice that we had to unpack the elements of the tuple. ... This might not suit your use case (especially if using a one-liner lambda function). An alternative is to use a list comprehension with the enumerate() ...
🌐
w3resource
w3resource.com › python-exercises › lambda › python-lambda-exercise-37.php
Python: Sort a list of lists by a given index of the inner list using lambda - w3resource
July 12, 2025 - # Define a function 'index_on_inner_list' that sorts a list of lists based on a specified index of inner lists def index_on_inner_list(list_data, index_no): # Sort the 'list_data' based on the specified 'index_no' of inner lists using the 'sorted' function # The 'key' parameter uses a lambda function to access the element at the given 'index_no' result = sorted(list_data, key=lambda x: x[index_no]) # Return the sorted list of lists return result # Create a list of tuples 'students' containing names and two additional elements for each student students = [ ('Greyson Fulton', 98, 99), ('Brady Ke
🌐
Medium
medium.com › marujosx › python-aws-lambda-13484341fb96
Python AWS Lambda. Index | by Flávio Filipe | Marujosx | Medium
September 29, 2022 - It was made using Yaml language where we describe our lambdas, the programming language and your version and connect AWS service. Eg: Call a lambda function by ApiGateway. For this example I made a basic function configuration, describing the path and the program language version (Python 3.9).
🌐
GitHub
github.com › aws › aws-cdk › issues › 9518
[aws-lambda-python] Unify `entry` field betwen aws-lambda-nodejs and aws-lambda-python · Issue #9518 · aws/aws-cdk
August 7, 2020 - new PythonFunction(this, 'MyFunc', { entry: path.join(__dirname, 'lambda', 'my_lambda.py') } But I received this error, which surprised me. Cannot find index file at /Users/blimmer/my-project/foo/src/my-func/lambda/my_lambda.py/index.py
Author   aws
🌐
Reddit
reddit.com › r/terraform › "unable to import module 'index': no module named 'index'"
r/Terraform on Reddit: "Unable to import module 'index': No module named 'index'"
July 4, 2023 -

I’m dealing with simple terraform app with lambda function;
I got this error :

{
“errorMessage”: “Unable to import module ‘index’: No module named ‘index’”,
“errorType”: “Runtime.ImportModuleError”,
“stackTrace”:
}

this is the main.tf file

provider "aws" {
  region = "us-east-1"
}
resource "aws_iam_role" "lambda_role" {
name   = "Spacelift_Test_Lambda_Function_Role"
assume_role_policy = <<EOF
{
 "Version": "2012-10-17",
 "Statement": [
   {
     "Action": "sts:AssumeRole",
     "Principal": {
       "Service": "lambda.amazonaws.com"
     },
     "Effect": "Allow",
     "Sid": ""
   }
 ]
}
EOF
}

resource "aws_iam_policy" "iam_policy_for_lambda" {
 
 name         = "aws_iam_policy_for_terraform_aws_lambda_role_1"
 path         = "/"
 description  = "AWS IAM Policy for managing aws lambda role"
 policy = <<EOF
{
 "Version": "2012-10-17",
 "Statement": [
   {
     "Action": [
       "logs:CreateLogGroup",
       "logs:CreateLogStream",
       "logs:PutLogEvents"
     ],
     "Resource": "arn:aws:logs:*:*:*",
     "Effect": "Allow"
   }
 ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "attach_iam_policy_to_iam_role" {
 role        = aws_iam_role.lambda_role.name
 policy_arn  = aws_iam_policy.iam_policy_for_lambda.arn
}

data "archive_file" "zip_the_python_code" {
type        = "zip"
source_dir  = "${path.module}/python/"
output_path = "${path.module}/python/index.zip"
}

resource "aws_lambda_function" "terraform_lambda_func" {
filename                       = "${path.module}/python/index.zip"
function_name                  = "Spacelift_Test_Lambda_Function"
role                           = aws_iam_role.lambda_role.arn
handler                        = "index.lambda_handler"
runtime                        = "python3.8"
depends_on                     = [aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role]
}

the index.py file

def lambda_handler(event, context):
   message = 'Hello {} !'.format(event['key1'])
   return {
       'message' : message
   }

🌐
Python Guides
pythonguides.com › get-index-of-element-in-python-list
Find Element Positions Using Python List Index Method
December 29, 2025 - The standard index() method only returns the first occurrence of an item. In my experience, you often need to find every single position where a value appears, such as finding all “Tesla” entries in a list of electric vehicles. I prefer using the Python enumerate() function combined with a list comprehension for this task.
🌐
Studytonight
studytonight.com › post › find-a-given-elements-index-in-python-list
Find a given element's index in Python List - Studytonight
August 31, 2021 - In the code above, the zip function ... the arguments and matches the value that we search for. It returns the index of the element that is being searched in the list. There are many different ways to accomplish the solve a problem ...
🌐
W3Schools
w3schools.com › python › ref_list_index.asp
Python List index() Method
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Training ... The index() method returns the position at the first occurrence of the specified value....